io_uring_pre...d_getsockname(3)

πŸ’… io_uring_prep_cmd_getsockname β€” bestie edition

okay so this is a page from the liburing Manual, and it's all about io_uring_prep_cmd_getsockname(3) β€” yes that's the whole name, it's a long one, she's dramatic, we love her for it πŸŽ€


✨ NAME ✨

io_uring_prep_cmd_getsockname β€” prepare a getsockname or getpeername request


🌸 SYNOPSIS 🌸

#include <sys/socket.h>
#include <liburing.h>

void io_uring_prep_cmd_getsockname(struct io_uring_sqe *sqe,
                                   int fd,
                                   struct sockaddr *sockaddr,
                                   socklen_t *sockaddr_len,
                                   int peer);

πŸ¦‹ DESCRIPTION πŸ¦‹

so io_uring_prep_cmd_getsockname(3) is the girl who prepares a getsockname/getpeername request. she doesn't do the whole thing herself, she just sets it up. main character energy but make it delegation πŸ’…

the submission queue entry sqe gets set up to fetch the locally bound address β€” or the peer address β€” of the socket file descriptor pointed at by sockfd.

the sockaddr parameter points to a region of size sockaddr_len where the output gets written. and sockaddr_len? the kernel modifies it on return to tell you how many bytes were actually written. so yeah, she comes back changed, that's normal, that's the vibe. ✨

which address you get depends on peer, no cap:

  • if peer is set to 0 β†’ you get the locally bound address
  • if peer is set to 1 β†’ you get the peer address

this function prepares an async getsockname(2) or getpeername(2) request. go read those man pages for the deets, they have the lore 🫢


πŸ’– RETURN VALUE πŸ’–

None. that's it. nothing. she returns void and she's at peace with it πŸ™ˆ


πŸ’€ ERRORS πŸ’€

the res field of the CQE is where the result lives. check the related man page for what values it could be, bestie.

and now the important part, listen up πŸ”₯ β€” where synchronous system calls would return -1 on failure and set errno to the actual error value, io_uring never uses errno. never ever. instead it returns the negated errno directly in the CQE res field. that's just how she operates.

⚠️ also, and this is the plot twist: differently from the equivalent system calls, if you try to use this operation on a non-socket file descriptor, the CQE error result is ENOTSUP instead of ENOSOCK. so like, not the error you'd expect. lowkey iconic of her to be different.

🌈 SEE ALSO 🌈


and that's the whole page bestie, we ate and left no crumbs πŸ“βœ¨

this one's from liburing-2.13, dated December 3, 2025 β€” so yeah, fresh off the press, mwah πŸ’‹ πŸ‘‘

πŸ“¦ where this page comes from