IP_RECVERR(2const)
β¨ IP_RECVERR π (a 2const girlie, from the Linux man-pages)
okay so bestie, welcome to the extended reliable error message passing page π β it lives in the IP_RECVERR constant, and it's giving "your datagram socket finally tells you the truth" energy.
π LIBRARY
Standard C library (libc, -lc) π«Ά
πΈ SYNOPSIS
#include <netinet/in.h> /* Definition of IP* constants */
#include <sys/socket.h>
int setsockopt(int sockfd, IPPROTO_IP, IP_RECVERR,
const int *enable, sizeof(int));
int getsockopt(int sockfd, IPPROTO_IP, IP_RECVERR,
int *enabled, sizeof(int));
struct sock_extended_err {
uint32_t ee_errno; /* error number */
uint8_t ee_origin; /* where the error originated */
uint8_t ee_type; /* type */
uint8_t ee_code; /* code */
uint8_t ee_pad;
uint32_t ee_info; /* additional information */
uint32_t ee_data; /* other data */
/* More data may follow */
};
#define SO_EE_ORIGIN_NONE 0
#define SO_EE_ORIGIN_LOCAL 1
#define SO_EE_ORIGIN_ICMP 2
#define SO_EE_ORIGIN_ICMP6 3
struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);
no cap, that struct is literally the whole plot of this page. π
π DESCRIPTION
So like β this flag turns on extended reliable error message passing. And the default? Disabled. π (she's shy at first, understandable.)
When you enable it on a datagram socket, all the errors that get generated will be queued up in a per-socket error queue. Then, when you receive an error from a socket operation, you can go get those errors by calling recvmsg(2) with the MSG_ERRQUEUE flag set. π
The sock_extended_err structure that describes the error gets passed in an ancillary message with the type IP_RECVERR and the level IPPROTO_IP. This is genuinely so useful for reliable error handling on unconnected sockets, fr fr. And the received data portion of the error queue? That contains the error packet. π
The IP_RECVERR control message contains a sock_extended_err structure.
.ee_errnoβ contains theerrnonumber of the queued error. π.ee_originβ is the origin code of where the error originated. π¦
The other fields are protocol-specific, iykyk.
The macro SO_EE_OFFENDER() returns a pointer to the address of the network object where the error originated from, given a pointer to the ancillary message. And if that address isn't known? Then the .sa_family member of the sockaddr contains AF_UNSPEC, and the other fields of the sockaddr are undefined. π (undefined behaviour, we do not romanticize her.)
IP uses the sock_extended_err structure as follows:
.ee_originis set toSO_EE_ORIGIN_ICMPfor errors received as an ICMP packet, orSO_EE_ORIGIN_LOCALfor locally generated errors. Unknown values should be ignored. periodt..ee_typeand.ee_codeare set from the type and code fields of the ICMP header. β¨.ee_infocontains the discovered MTU forEMSGSIZEerrors. π- The message also contains the
sockaddr_inof the node caused that the error, which can be accessed with theSO_EE_OFFENDER()macro.
The .sin_family field of the SO_EE_OFFENDER() address is AF_UNSPEC when the source was unknown. When the error originated from the network, all IP options (IP_OPTIONS(2const), IP_TTL(2const), etc.) enabled on the socket and contained in the error packet are passed as control messages. And the payload of the packet causing the error is returned as normal payload. π
ok bestie important one: TCP has no error queue.MSG_ERRQUEUEis not permitted onSOCK_STREAMsockets.IP_RECVERRis valid for TCP, but all errors are returned by socket function return orSO_ERRORonly. π€
For raw sockets, IP_RECVERR enables passing of all received ICMP errors to the application β otherwise errors are reported only on connected sockets. π§
π ERRORS
See IPPROTO_IP(2const). See setsockopt(2). See ip(7). π
β STANDARDS
Linux. that's it, that's the standards section, she's a Linux exclusive π
π HISTORY
Linux 2.2. vintage but still iconic, no notes. π₯
π¦ SEE ALSO
IPPROTO_IP(2const), setsockopt(2), ip(7)
and that's the whole page, bestie!! πΈ
this was pulled straight from Linux man-pages 6.20, dated 2025-11-25 β mwah, go enable your error queue and slay πβ¨π
π¦ 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