Hi
I have a need to get the MTU of the outgoing interface given an IPv4 or IPv6 destination address.
I have had several attempts at getting this information using different hacks.
The first hack I tried was using RTNETLINK. However, given the destination address, I was given the Path MTU which might be less than the MTU of the outgoing interface. The code is at
http://www.wand.net.nz/~mjl12/netlink-mtu.c
The caveat with that code is that IPv6 routes seem to have an expiry set that is not related to any PMTU caching. I can get the interface's MTU using an IPv4 address flushing the route cache first, and then quering for the destination.
The second attempt I had was using a similar technique to tracepath. That too returned the path MTU given a destination.
http://www.wand.net.nz/~mjl12/udp-mtu.c
The third attempt was to use SIOCGIFCONF to get a list of interfaces and addresses, and then match the interface address with whatever was returned by getsockname. I found that I was only returned AF_INET addresses, which does not fulfill my desire to have both AF_INET and AF_INET6.
http://www.wand.net.nz/~mjl12/ioctl-mtu.c
What is the suggested way to get the outgoing interface's MTU under Linux?
Matthew - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Alternatively you can use the ioctls documented in the netdevice man page to retrieve all the local interface mtu's.
Neil -- /*************************************************** *Neil Horman *Software Engineer *Red Hat, Inc. *nhorman@redhat.com *gpg keyid: 1024D / 0x92A74FA1 *http://pgp.mit.edu ***************************************************/ - : send the line "unsubscribe linux-net" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html