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 β€” sockfd is not a valid file descriptor. bestie that's not even a real fd. πŸ™ˆ
  • EINVAL β€” sockfd is a file descriptor, sure, but it's not one that sockatmark() 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() returns 1, then you can read the out-of-band data using the MSG_OOB flag of recv(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 the SIGURG signal. signal-handler-safe, no chaos. 🫢
  • sockatmark() is implemented using the SIOCATMARK ioctl(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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms