Socket.DontFragment Property


Gets or sets a value that specifies whether the Socket allows Internet Protocol (IP) datagrams to be fragmented.

 property bool DontFragment { bool get(); void set(bool value); };
public bool DontFragment { get; set; }
member this.DontFragment : bool with get, set
Public Property DontFragment As Boolean

Property Value


true if the Socket doesn't allow datagram fragmentation; otherwise, false. The default is true.


This property can be set only for sockets in the InterNetwork or InterNetworkV6 families.

An error occurred when attempting to access the socket.

The Socket has been closed.


The following code example demonstrates the use of the DontFragment property.

static void ConfigureUdpSocket(Socket^ udpSocket)

    // Set the Don't Fragment flag.
    udpSocket->DontFragment = true;
    // Enable broadcast.
    udpSocket->EnableBroadcast = true;
    // Disable multicast loopback.
    udpSocket->MulticastLoopback = false;
    Console::WriteLine("Udp Socket configured:");
    Console::WriteLine("  DontFragment {0}", 
    Console::WriteLine("  EnableBroadcast {0}", 
    Console::WriteLine("  MulticastLoopback {0}", 
static void ConfigureUdpSocket(Socket udpSocket)
    // set the Don't Fragment flag.
    udpSocket.DontFragment = true;
    // Enable broadcast.
    udpSocket.EnableBroadcast = true;

    // Disable multicast loopback.
    udpSocket.MulticastLoopback = false;

    Console.WriteLine("Udp Socket configured:");
    Console.WriteLine($"  DontFragment {udpSocket.DontFragment}");
    Console.WriteLine($"  EnableBroadcast {udpSocket.EnableBroadcast}");
    Console.WriteLine($"  MulticastLoopback {udpSocket.MulticastLoopback}");


Datagrams require fragmentation when their size exceeds the Maximum Transfer Unit (MTU) of the transmission medium. Datagrams may be fragmented by the sending host (all Internet Protocol versions) or an intermediate router (Internet Protocol Version 4 only). If a datagram must be fragmented, and the DontFragment option is set, the datagram is discarded, and an Internet Control Message Protocol (ICMP) error message is sent back to the sender of the datagram.

Setting this property on a Transmission Control Protocol (TCP) socket will have no effect.

Applies to