I am writing a file transferring program over TCP.
I want to set the don't fragment flag on IP
On a socket this is what I want to do:
int val = 1; setsockopt(sd, IPPROTO_IP, IP_DONTFRAG, &val, sizeof(val));
However IP_DONTFRAG
does not seem available on Mac OS. Am I missing something? or did I forget to include it correctly?
Thanks in advance if anyone knows
--Sam
The DF bit is typically used for path MTU (PMTU) discovery automatically by the operating system with TCP connections. If anything, you may have a socket option for disabling PMTU discovery which will have the effect of never setting DF (it's the IP_MTU_DISCOVER socket option on linux). If you leave PMTU discovery on, it will have the effect of always setting DF.
It wouldn't make sense to set/unset it on a packet-by-packet basis because you're using TCP and TCP operates on segments, not packets. If you want to set packet-level stuff, you need to use a lower-layer protocol.
The Don't Fragment
bit is typically set on all TCP packets anyway. You don't have to do any special to achieve this.