sockatmark(3)
π sockatmark(3) π
okay bestie, gather round, because today we're talking about sockatmark(3) β a little function from the Library Functions Manual slaying in the Standard C library (libc, -lc). no cap. πΈ
β¨ NAME β¨
sockatmark β figure out whether a socket is chillin' at the out-of-band mark π
π LIBRARY π
Standard C library (libc, -lc) π«Ά
πͺ SYNOPSIS πͺ
#include <sys/socket.h>
int sockatmark(int sockfd);
π Feature Test Macro Requirements for glibc (peep feature_test_macros(7)) π
So like, for sockatmark() you gotta have:
_POSIX_C_SOURCE >= 200112L
π DESCRIPTION π
sockatmark() hands you back a value that tells you whether or not the socket that the file descriptor sockfd points at is currently at the out-of-band mark. π¦
- if the socket is at the mark β it returns
1 - if the socket is not at the mark β it returns
0
and listen, the important part: this function does not remove the out-of-band mark. it's a look, not a touch. πβ¨
π RETURN VALUE π
A successful call to sockatmark() returns 1 if the socket is at the out-of-band mark, or 0 if it's not. π
On error? It returns -1 and errno gets set to tell you what went wrong. π
π ERRORS π
EBADFβsockfdis not a valid file descriptor. bestie that's not even a real fd. πEINVALβsockfdis a file descriptor, sure, but it's not one thatsockatmark()can be applied to. wrong vibe, wrong socket. π«
π ATTRIBUTES π
For the deets on what all these terms even mean, go read attributes(7). π
- Interface:
sockatmark()β Attribute: Thread safety β Value:MT-Safeπ₯
so yeah, she's MT-Safe. multithreaded icon behaviour, we love to see it. β¨
π STANDARDS π
POSIX.1-2008. periodt. π
π°οΈ HISTORY π°οΈ
- glibc
2.2.4 POSIX.1-2001
she's been around. seasoned queen. π
π NOTES π
- if
sockatmark()returns1, then you can read the out-of-band data using theMSG_OOBflag ofrecv(2). that's the whole point, bestie. π - out-of-band data is supported only on some stream socket protocols. so like, check before you commit. π§
sockatmark()can safely be called from a handler for theSIGURGsignal. signal-handler-safe, no chaos. π«Άsockatmark()is implemented using theSIOCATMARKioctl(2)operation. fun fact, iykyk. π
π BUGS π
Prior to glibc 2.4, sockatmark() did not work. π
literally did not work. if you're on ancient glibc, this is not a you problem, it's a them problem. π
π EXAMPLES π
this next bit? chef's kiss. π₯ the code below can be used after you receive a SIGURG signal to read (and discard) all data up to the mark, and then read the byte of data at the mark:
char buf[BUF_LEN];
char oobdata;
int atmark, s;
for (;;) {
atmark = sockatmark(sockfd);
if (atmark == -1) {
perror("sockatmark");
break;
}
if (atmark)
break;
s = read(sockfd, buf, BUF_LEN);
if (s == -1)
perror("read");
if (s <= 0)
break;
}
if (atmark == 1) {
if (recv(sockfd, &oobdata, 1, MSG_OOB) == -1) {
perror("recv");
...
}
}
like, read everything up to the mark, yeet it, then grab the one byte at the mark with MSG_OOB. ate. π
π SEE ALSO π
fcntl(2), recv(2), send(2), tcp(7) π
and that's the whole page, bestie!! this one came from Linux man-pages 6.20, dated 2026-02-08 β so if you cite her, cite her right. mwah, go read your sockets. πβ¨ππ¦πΈπ«Ά
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2006, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms