Don't Fragment flag in Java

2019-09-12 05:42发布

问题:

Is it possible in Java to send a UDP packet with the "Don't Fragment" flag set using the standard API?

I don't see any relevant options on DatagramSocket or DatagramChannel.setOption (or better: StandardSocketOptions).

回答1:

The "Don't Fragment" flag is part of IP, not TCP or UDP. IP is the protocol 1 layer below TCP and UDP (TCP and UDP packets are wrapped in IP).

You would need the ability to create a raw socket, which is not available in standard Java. There seems to be a library called "RockSaw" which might be of use. Be aware that your program will need to have root/administrator permissions to access raw sockets.



标签: java udp