STRUCT SOCKOPT(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct sockopt(9) β€” the Kernel API Manual era

okay so bestie, welcome to struct sockopt(9), straight out of the Kernel API Manual ✨ this one's a little container that holds your socket option values and honestly it's giving main character energy for something so smol πŸŽ€


🌸 SYNOPSIS 🌸

struct sockopt {
    struct iov_iter iter_in;
    struct iov_iter iter_out;
    int optlen;
 };

πŸ¦‹ Members πŸ¦‹

  • iter_in β€” the iov_iter you use for reading optval with the content coming from the caller πŸ’– use copy_from_iter, because this iov's direction is ITER_SOURCE (iykyk, direction matters, don't come for me)
  • iter_out β€” the iov_iter that lets protocols update optval data on over to userspace 🌈 use _copy_to_iter, since this iov's direction is ITER_DEST β€” literally the opposite vibe of iter_in, slay
  • optlen β€” this one's doing double duty fr fr: it's both the input (buffer size) and the output (returned data size) πŸ‘‘ one field, two jobs, she's booked and busy

✨ Description ✨

It's a type-safe wrapper for socket option data that works with both user and kernel buffers 🫢 no cap, that's the whole point.

And the optlen field? It lets callbacks return a specific length value that's independent of the bytes written via copy_to_iter 😭 so you can say "bestie, the answer is this long" while writing a totally different number of bytes. iconic behaviour, honestly.


πŸ”₯ SEE ALSO πŸ”₯

  • Kernel file ./include/linux/net.h
  • enum sock_type(9)
  • enum sock_shutdown_cmd(9)
  • struct socket(9)

that's the whole page 🧚 mwah πŸ’‹

sign-off szn: this little gem lives in ./include/linux, its date stamp says October 2026, and it goes by struct sockopt(9) β€” periodt πŸ’…βœ¨

πŸ“¦ where this page comes from