1

I am working on UDP socket programming, and I have to stop the transmission in application, if requested data is more than MTU value.

To achieve this I have to read MTU value but I don't know how to get MTU value (could be by using getsockopt()) in case of UDP sockets.

Is there any way to find the MTU value with UDP sockets?

linuxman
  • 83
  • 3
  • 10

2 Answers2

0

The ifconfig command is giving the MTU. By straceing it I see that it uses ioctl (on some socket file descriptor) with SIOCGIFMTU to query the MTU

See also this related question (about getting in C code same info as ifconfig)

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

In linux, it's not a UDP thing—it's an IP thing:

$ man 7 ip

It explains everything. You're looking for the IP_MTU socket option. It's pretty complicated, so you'll definitely want to read that man page. While you're at it, you should also man udp and man 7 socket.

It took me forever to figure this out, because it wasn't mentioned in man sys_socket.h!

enigmaticPhysicist
  • 1,518
  • 16
  • 21