MSDN Documentation

AddressFamily Enumeration

Namespace: System.Net
Assembly: System.Net.Primitives.dll

Specifies the base address family used by the Socket class and other networking classes.

Syntax


public enum AddressFamily

Members

The AddressFamily enumeration contains the following members:

Member Description Value
InterNetwork The Internet Protocol version 4 (IPv4) address family. 2
InterNetworkV6 The Internet Protocol version 6 (IPv6) address family. 23
Unknown The address family is unknown. 0
BitsOnlyHousekeeping Reserved for internal use. 1
Unspecified An unspecified address family. 0
IM64 DECnet IV address family. 4
NSap NSAP address family. 6
NSapHardware NSAP hardware address family. 7
OSI OSI address family. 8
ECMA European Computer Manufacturers Association (ECMA) address family. 9
DataLink The Data Link address family. 10
Cluster DECcluster address family. 11
NetBios NetBIOS address family. 12
Datakit Datakit address family. 13
CCITT CCITT address family. 14
SNA Systems Network Architecture (SNA) address family. 15
DecNet DECnet address family. 16
DecDirect DEC Direct address family. 17
NetDES Reserved for internal use. 18
BlueRidge Reserved for internal use. 19
Ipx Internet Protocol over IPX/SPX. 20
AppleTalk AppleTalk address family. 21
Banyan Banyan VINES address family. 22
VINES Banyan VINES address family. 22
NativeMax Maximum address family value. 23
Any Any address family. 32768
Max Maximum address family value. 65535

Remarks

This enumeration is used with the Socket constructor to specify the address family to be used for the socket. Common values include AddressFamily.InterNetwork for IPv4 and AddressFamily.InterNetworkV6 for IPv6.

Examples

The following C# code example demonstrates how to create an IPEndPoint using AddressFamily.InterNetwork:


using System;
using System.Net;
using System.Net.Sockets;

public class Example
{
    public static void Main(string[] args)
    {
        // Create an IPEndPoint for IPv4
        IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Loopback, 11000);
        Console.WriteLine($"Created IPEndPoint: {ipEndPoint.Address} on port {ipEndPoint.Port}");
        Console.WriteLine($"Address Family: {ipEndPoint.AddressFamily}");

        // Example of creating a Socket with IPv4
        using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
        {
            Console.WriteLine("Socket created for IPv4 TCP communication.");
        }
    }
}
                

Requirements

Namespace: System.Net

Assembly: System.Net.Primitives.dll

Framework: .NET Framework 1.1, .NET Framework 2.0, .NET Framework 3.0, .NET Framework 3.5, .NET Framework 4.0, .NET Framework 4.5, .NET Core 1.0, .NET Core 1.1, .NET Core 2.0, .NET Core 2.1, .NET Core 2.2, .NET Standard 1.3, .NET Standard 1.4, .NET Standard 1.6, .NET Standard 2.0, .NET 5, .NET 6, .NET 7, .NET 8