kernel_recvmsg(9)
π kernel_recvmsg β bestie edition
okay so this is a page from the Kernel API Manual (yes, the kernel kernel, we're in kernel space rn, no cap) and it's about kernel_recvmsg, which is literally how you receive a message from a socket when you're living that kernel-space life. sit down, grab a strawberry π, let's get into it.
β¨ NAME β¨
kernel_recvmsg β receive a message from a socket, but make it kernel space π«Ά
β¨ SYNOPSIS β¨
int kernel_recvmsg (struct socket *sock , struct msghdr *msg , struct
kvec *vec , size_t num , size_t size , int flags );
that's the whole signature, copy it exactly, do not freestyle it π
β¨ ARGUMENTS β¨
sockβ the socket you're receiving the message from. your source. your origin story. πΈmsgβ the received message. this is where the good stuff lands. πvecβ input scatter/gather array for the message data. the s/g icon of the group chat. β¨numβ the size of that input s/g array. how many of them there are. πsizeβ number of bytes to read. yes, bytes. respect the units. π¦flagsβ message flags, likeMSG_DONTWAIT, etc... the "etc..." is doing a lot of heavy lifting here but that's what the page says, iykyk π
β¨ DESCRIPTION β¨
so here's the tea π΅ β on return, the msg structure contains the scatter/gather array that you passed in through the vec argument. and not just as-is, bestie: the array gets modified so that it consists of the unfilled portion of the original array. it slims down. it's giving what's left over, and honestly? iconic. π
the returned value is the total number of bytes received, or an error. that's it. total bytes, or error. two outcomes, no in-between, periodt. π₯
β¨ SEE ALSO β¨
the page also shouts out the kernel file ./net/socket.c and a whole friend group of related functions β go say hi to all of them, don't leave anyone on read π:
move_addr_to_kernel(9)move_addr_to_user(9)sock_read_xattr(9)sock_alloc_file(9)sock_from_file(9)sockfd_lookup(9)sock_alloc(9)sock_release(9)sock_sendmsg(9)kernel_sendmsg(9)sock_recvmsg(9)sock_create_lite(9)__sock_create(9)sock_create(9)sock_create_kern(9)sock_register(9)sock_unregister(9)kernel_bind(9)kernel_listen(9)kernel_accept(9)kernel_connect(9)kernel_getsockname(9)kernel_getpeername(9)kernel_sock_shutdown(9)kernel_sock_ip_overhead(9)
okay that's the whole page, you ate that π β¨ mwah π
this cutie lives in ./net and the page is dated October 2026, so likeβ¦ future vibes, main character energy, kernel_recvmsg(9) forever πππ¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms