ENOPROTOOPT
Linux / POSIXERRORCommonNetworkHIGH confidence
Protocol Not Available
Production Risk
Programming error; check option-to-protocol compatibility in the man page.
What this means
ENOPROTOOPT (errno 92) is returned by getsockopt() or setsockopt() when the requested socket option is not supported by the protocol.
Why it happens
- 1Setting TCP_NODELAY on a UDP socket
- 2Using SO_KEEPALIVE with a protocol that does not support it
- 3Setting an IPv6-only option on an IPv4 socket
How to reproduce
setsockopt() with a TCP option on a UDP socket.
trigger — this will error
trigger — this will error
int sockfd = socket(AF_INET, SOCK_DGRAM, 0); int one = 1; // TCP_NODELAY is a TCP option, not valid for UDP setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); // Returns -1, errno = ENOPROTOOPT
expected output
setsockopt: Protocol not available (ENOPROTOOPT)
Fix
Use the correct level and option for the socket type
WHEN When setting socket options
Use the correct level and option for the socket type
// For UDP, use SOL_SOCKET level options setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); // TCP_NODELAY is only for TCP sockets: int tcp_sockfd = socket(AF_INET, SOCK_STREAM, 0); setsockopt(tcp_sockfd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
Why this works
Each option belongs to a specific protocol level (SOL_SOCKET, IPPROTO_TCP, IPPROTO_UDP, etc.).
Sources
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev