in_pktinfo(2type)
β¨ in_pktinfo(2type) β¨
okay bestie, pull up a chair, because this page from the in_pktinfo(2type) manual is literally about knowing exactly where your packets came from and where they're headed. it's giving "packet detective" energy and we're obsessed π
πΈ NAME πΈ
in_pktinfo β all the tea about the incoming packet π«β¨
π LIBRARY π
Standard C library (libc, -lc). yes, the classic. the blueprint. no cap.
π¦ SYNOPSIS π¦
#include <netinet/in.h>
struct in_pktinfo {
unsigned int ipi_ifindex; /* Interface index */
struct in_addr ipi_spec_dst; /* Local address */
struct in_addr ipi_addr; /* Header Destination address */
};
look at her. three fields. main character energy in a struct. π
π₯ DESCRIPTION π₯
π recvmsg(2)
when recvmsg(2) hands this struct back to you, here's what you're lookin at:
.ipi_ifindexis the unique index of the interface the packet was received on. like, that specific one. no imposters. π.ipi_spec_dstis the preferred source address for replies to the given packet β aka "hey, if you're gonna clap back, reply from this address." π«Ά.ipi_addris the destination address in the packet header.
and here's the plot twist π: these addresses are usually the same, but they can differ for broadcast or multicast packets. and depending on the configured routes, .ipi_spec_dst might lowkey belong to a different interface from the one that actually received the packet. the way that routes can just switch things up on youβ¦ iconic but also unhinged. π
π sendmsg(2)
so when you're sending, it's a whole different vibe:
- if
IP_PKTINFOis passed tosendmsg(2)and.ipi_spec_dstis not zero, then it gets used as the local source address, for the routing table lookup, and for setting up IP source route options. triple threat fr fr. π - when
.ipi_ifindexis not zero, the primary local address of the interface specified by the index overwrites.ipi_spec_dstfor the routing table lookup. yeah β it just overrides it like that. rude but that's the rules. π .ipi_addr? ignored. π not even invited to the function call. sorry girl, you're benched.
β οΈ heads up bestie: the overwrite thing in that second bullet is real and it's coming for your.ipi_spec_dst. set.ipi_ifindexwith intention, iykyk.
β STANDARDS β
Linux. that's it. that's the standard. π§β¨
π¦ HISTORY π¦
Linux 2.2 β so she's been around a minute, but she still ate. π
π SEE ALSO π
and that's the page!! π this one came from Linux man-pages 6.20, dated 2025-11-26 β so you know it's fresh π. now go forth and read your packet headers like the networking baddie you are. periodt. π πΈπ¦
π¦ 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