How can I force set the MTU with C code?

1.8k Views Asked by At

I have an issu with my device when I connect by TCP sockets, because the client send the MSS in the SYN connection and the server (my device) is setting with the same MSS, but I don't want set this MSS in my device.

So how can I force setting this value in the MSS?

I tried setting the MTU value with the setsockopt function with the IP_DONTFRAG

1

There are 1 best solutions below

0
On

You should be able to call setsockopt with the TCP_MAXSEG option to set the TCP maximum segment size. Take a look at tcp(4) for the available options. You probably have to set the option before connect or listen.

As for setting the IP MTU, the IP_DONTFRAG option will cause the packet to be dropped if a segment has a smaller MTU. The IP layer should negotiate to a reasonable MTU value by retransmitting a smaller packet after receiving a "fragmentation needed" response. TCP segments and IP packets are at different layers of the protocol stack -- in other words, a single TCP segment can span multiple IP packets. Changing the size of the IP packet does not effect the size of the TCP segment.