io_uring_prep_getsockname(3)

πŸ“¦ version 2.13, in fedora 44

πŸ’– io_uring_prep_getsockname β€” liburing manual, bestie edition πŸ’–

okay so you're in the liburing manual, section 3, and the star of the show today is io_uring_prep_getsockname πŸ’…


✨ NAME ✨

io_uring_prep_getsockname β€” prepares a getsockname or getpeername request 🫢


🌸 SYNOPSIS 🌸

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

void io_uring_prep_getsockname(struct io_uring_sqe *sqe,
                               int sockfd,
                               struct sockaddr *sockaddr,
                               socklen_t *sockaddr_len,
                               int peer);

πŸ¦‹ DESCRIPTION πŸ¦‹

So the way that io_uring_prep_getsockname(3) works is: it preps a getsockname/getpeername request for you, no cap. ✨

The submission queue entry sqe gets set up so it'll go fetch the locally bound address or the peer address of the socket file descriptor that sockfd is pointing at.

Now sockaddr β€” she points to a region of size sockaddr_len, and that's where the output gets written. πŸ“ And sockaddr_len gets modified by the kernel to show how many bytes were actually written. The kernel edits your length for you, iconic behavior honestly.

Which address do you get? Depends on peer:

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

And like… this function is literally just preparing an async getsockname(2) or getpeername(2) request, so if you want the full tea, go read those man pages. πŸ“


πŸ’œ RETURN VALUE πŸ’œ

None. That's it. Nothing. Nada. It returns void, bestie, because all the actual results show up in the CQE. πŸ™ˆ


πŸ”₯ ERRORS πŸ”₯

The res field of the CQE is where the result of the operation lands. Peep the related man page for what values are possible. πŸ‘‘

⚠️ Big important thing: where synchronous system calls would return -1 on failure and set errno to the actual error value, io_uring never uses errno. Instead it returns the negated errno directly in the CQE res field. So no errno snooping, periodt.

And another one that's different from the syscalls, so listen up: if the user tries to use this operation on a non-socket file descriptor, the CQE error result is -ENOTSUP instead of ENOSOCK. Yeah. Different error, different vibe. πŸ’€


🌈 SEE ALSO 🌈


and that's the whole page, bestie!! πŸŽ€ this was liburing-2.13, dated Dec 3, 2025 β€” go get those socket addresses, you absolute main character πŸ‘‘πŸ’–βœ¨

πŸ“¦ where this page comes from