IP_PKTINFO(2const)

πŸ“¦
version 6.20 Β· 4 versions
, in arch rolling, nixpkgs unstable

πŸ’– IP_PKTINFO(2const) πŸ’–

okay bestie, sit down, hydrate, and let me tell you about IP_PKTINFO β€” a little socket option from the Linux manual pages (section 2const, the constants girlies) that's all about info on the incoming packet. πŸ¦‹

πŸ“š LIBRARY

Standard C library (libc, -lc). yes ma'am, the classic. πŸ’…

✨ SYNOPSIS

#include <netinet/in.h>  /* Definition of IP* constants */
#include <sys/socket.h>

int setsockopt(int sockfd, IPPROTO_IP, IP_PKTINFO,
               const int *enable, sizeof(int));

🌸 DESCRIPTION

So here's the tea, bestie. When you turn this on, the socket gets to pass you an IP_PKTINFO ancillary message, and inside that message lives a in_pktinfo(2type) structure that serves up some info about the incoming packet. ✨

lowkey important: this works only for datagram oriented sockets. no cap.

The argument is a flag that tells the socket whether the IP_PKTINFO message should be passed or not. that's it, that's the whole vibe check.

The message itself can be sent/retrieved only as a control message with a packet, using recvmsg(2) or sendmsg(2). so like, it rides along with the packet, it doesn't travel solo. 🫢

Not supported for SOCK_STREAM sockets. πŸ’€ stream sockets, you are NOT invited to this party.


😭 ERRORS

go read IPPROTO_IP(2const). go read setsockopt(2). go read ip(7). they got the error lore, bestie, I'm just the messenger. πŸŽ€

πŸ¦‹ VERSIONS

Some BSD sockets implementations hand out IP_RCVDSTADDR and IP_RECVIF socket options to grab the destination address and the interface of received datagrams. Linux said "not me doing two options when one can eat" and gave us the way more general IP_PKTINFO for the exact same task. ate. πŸ‘‘

⭐ STANDARDS

Linux. periodt. πŸ’…

πŸ•°οΈ HISTORY

Linux 2.2. old money, honestly.


πŸ‘€ SEE ALSO


and that's the whole page, bestie!! 🧚 this icon was brought to you by Linux man-pages 6.20, dated 2025-12-01 β€” bookmark it, screenshot it, tell your group chat about it, mwah πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ 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