IP_RECVERR(2const)

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

✨ 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 the errno number 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_origin is set to SO_EE_ORIGIN_ICMP for errors received as an ICMP packet, or SO_EE_ORIGIN_LOCAL for locally generated errors. Unknown values should be ignored. periodt.
  • .ee_type and .ee_code are set from the type and code fields of the ICMP header. ✨
  • .ee_info contains the discovered MTU for EMSGSIZE errors. πŸ‘‘
  • The message also contains the sockaddr_in of the node caused that the error, which can be accessed with the SO_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_ERRQUEUE is not permitted on SOCK_STREAM sockets. IP_RECVERR is valid for TCP, but all errors are returned by socket function return or SO_ERROR only. 😀

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