This documentation is archived and is not being maintained.

Socket.SetIPProtectionLevel Method

Set the IP protection level on a socket.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

public void SetIPProtectionLevel(
	IPProtectionLevel level


Type: System.Net.Sockets.IPProtectionLevel
The IP protection level to set on this socket.


The level parameter cannot be IPProtectionLevel.Unspecified. The IP protection level cannot be set to unspecified.


The AddressFamily of the socket must be either InterNetworkV6 or InterNetwork.

The SetIPProtectionLevel method enables restricting an a IPv6 or IP socket to listen on a specified scope, such as addresses with the same link local or site local prefix. This socket option enables applications to place access restrictions on IPv6 or IP sockets. Such restrictions enable an application running on a private LAN to simply and robustly harden itself against external attacks. This socket option can also be used to remove access restrictions if the level parameter is set to Unrestricted. This socket option widens or narrows the scope of a listening socket, enabling unrestricted access from public and private users when appropriate, or restricting access only to the same site, as required.

This socket option has defined protection levels specified in the IPProtectionLevel enumeration.

The SetIPProtectionLevel method is used to enable or disable Network Address Traversal (NAT) for a Socket instance. NAT traversal may be provided using Teredo, 6to4, or an ISATAP tunnel.

When the level parameter is set to EdgeRestricted, or Restricted, this explicitly disables NAT traversal for a Socket instance.

When the level parameter is set to EdgeRestricted, this may allow NAT traversal for a Socket depending on firewall rules in place on the system.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.