Setting TCP receive window in C and working with tcpdump in Linux Setting TCP receive window in C and working with tcpdump in Linux linux linux

Setting TCP receive window in C and working with tcpdump in Linux


You need to also use TCP_WINDOW_CLAMP

rcvbuf = 2048;setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)& rcvbuf, sizeof(rcvbuf));clamp = 1024;setsockopt(sock, SOL_SOCKET, TCP_WINDOW_CLAMP, (char *)& clamp, sizeof(clamp));

Note the rcvbuf is twice the clamp, it could be more. You can let it autotune, the window clamp will still work. This isn't portable.


The receive buffer size can be reduced only before you connect the socket - you can increase it at any time. What order are you calling sockopt() in relative to connect()?


For TCP, the rwnd value is to be passed during recv.

recv(sock, buf, rwnd, 0);

This shall receive 1024 bytes.