3

How do I find the path MTU between connection? I need this to define the packet size of my UDP connection. Is there things like Path MTU Discovery in .Net?

Yves M.
  • 29,855
  • 23
  • 108
  • 144
Syaiful Nizam Yahya
  • 4,196
  • 11
  • 51
  • 71

3 Answers3

2

i have found a way(workaround) to find the path mtu for udp on c#. just try send udp packet with udpclient.dontfragment set to true. if it throws an exception, reduce the packet size until no exception is thrown. if anybody would like to see some sample, just ask.

Syaiful Nizam Yahya
  • 4,196
  • 11
  • 51
  • 71
  • 1
    The lower MTU may be along the path. So you don't get exception, the packet is sent, but not received. You have to send some packet sizes and make other end point to sent you some ACK packets back to do MTU discovery. – xmedeko Oct 18 '18 at 07:22
  • 1
    "Any device along the path whose MTU is smaller than the packet will drop such packets and send back an ICMP "Destination Unreachable (Datagram Too Big)" message containing its MTU." https://en.wikipedia.org/wiki/Maximum_transmission_unit#Path_MTU_Discovery – aminhotob Oct 30 '18 at 14:33
1

Taken from here:

winsock doesn't support reporting the discovered MTU, even though other TCP/IP stacks do (e.g. AIX through a socket option IP_GETPMTU). As winsock cannot report that, .NET can't provide an API (which would have to be on top of winsock).

Community
  • 1
  • 1
bitbonk
  • 48,890
  • 37
  • 186
  • 278
1

Have you tried using libpcap with C#? There is a library called SharpPCap that you can use to find the PMTU.

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
isyi
  • 1,282
  • 1
  • 11
  • 11
  • Also, can I get your sample code for using Udpclient to find the Path MTU without libpcap? – isyi Feb 06 '12 at 22:37