While doing some exercises about sockets, I wrote the code below.
const int socketfd = socket(AF_INET, SOCK_STREAM, 0);
int tcprcvbuf;
socklen_t tcprcvbuflen = sizeof(tcprcvbuf);
getsockopt(socketfd, SOL_SOCKET, SO_SNDBUF, &tcprcvbuf, &tcprcvbuflen);
printf("Default send buffer (TCP): %dn", tcprcvbuf);
The output is:
Default send buffer (TCP): 16384
While the result for cat /proc/sys/net/core/wmem_default
is 212992, 13 times greater than 16384.
According to socket(7) man pages:
SO_SNDBUF
Sets or gets the maximum socket send buffer in bytes. The kernel doubles this value (to allow space for bookkeeping overhead)
when it is set using setsockopt(2), and this doubled value is returned by getsockopt(2). The default value is set by the
/proc/sys/net/core/wmem_default file and the maximum allowed value is set by the /proc/sys/net/core/wmem_max file. The minimum
(doubled) value for this option is 2048
While playing around with setsockopt with the same params I noticed that setting any value below 2304 will give me 4608 (the double, as expected). Any value above it will give me the expected double of it. But the manual says the minimum (doubled) value would be 2048.
What am I missing here?