Re: [OFFTOPIC] Computing the MTU

Andi Kleen (
19 Nov 1997 14:18:06 +0100

Richard Gooch <rgooch@atnf.CSIRO.AU> writes:

> Hi, all. Is there a portable way of determining the path MTU for a
> TCP connection? What about for a UDP connection? I'd like to be able
> to send UDP packets over congested networks with minimum packet loss
> due to fragmentation. Can it be done?

That's a limitation of the socket API. Actually (at least in 2.1, haven't
checked 2.0) the kernel does all the hard work of pmtu discovery for you
when you turn it on with
val=1; setsockopt(..., SOL_IP, IP_PMTUDISC, &val, sizeof val);
but there is currently no way to get the MTU information to the user
program. You'll get a EMSGSIZE error code back from the udp socket call.
Of course you could first retrieve the original interface MTU and then
do the PMTU guessing like described in the RFC (see net/ipv4/route.c:
guess_mtu()), but that's silly of course, because the kernel already did this.
I think a simple getsockopt() could be added for this.