Socket.DontFragment Property

Definition

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

C#
public bool DontFragment { get; set; }

Property Value

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

Exceptions

The socket is not in the InterNetwork family.

An error occurred when attempting to access the socket.

The Socket has been closed.

Examples

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

C#
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}");
}

Remarks

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 has no effect.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1