Show / Hide Table of Contents

Class NetServices

Helper class to provide network services.

Inheritance
System.Object
NetServices
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: SIPSorcery.Sys
Assembly: SIPSorcery.dll
Syntax
public class NetServices

Properties

| Improve this Doc View Source

InternetDefaultAddress

The local IP address this machine uses to communicate with the Internet.

Declaration
public static IPAddress InternetDefaultAddress { get; }
Property Value
Type Description
System.Net.IPAddress
| Improve this Doc View Source

InternetDefaultIPv6Address

The local IPv6 address this machine uses to communicate with the Internet.

Declaration
public static IPAddress InternetDefaultIPv6Address { get; }
Property Value
Type Description
System.Net.IPAddress
| Improve this Doc View Source

LocalIPAddresses

The list of IP addresses that this machine can use.

Declaration
public static List<IPAddress> LocalIPAddresses { get; }
Property Value
Type Description
System.Collections.Generic.List<System.Net.IPAddress>
| Improve this Doc View Source

SupportsDualModeIPv4PacketInfo

Declaration
public static bool SupportsDualModeIPv4PacketInfo { get; }
Property Value
Type Description
System.Boolean

Methods

| Improve this Doc View Source

CreateBoundSocket(Int32, IPAddress, ProtocolType, Boolean, Boolean)

Attempts to create and bind a socket with defined protocol. The socket is always created with the ExclusiveAddressUse socket option set to accommodate a Windows 10 .Net Core socket bug where the same port can be bound to two different sockets, see https://github.com/dotnet/runtime/issues/36618.

Declaration
public static Socket CreateBoundSocket(int port, IPAddress bindAddress, ProtocolType protocolType, bool requireEvenPort = false, bool useDualMode = true)
Parameters
Type Name Description
System.Int32 port

The port to attempt to bind on. Set to 0 to request the underlying OS to select a port.

System.Net.IPAddress bindAddress

Optional. If specified the socket will attempt to bind using this specific address. If not specified the broadest possible address will be chosen. Either IPAddress.Any or IPAddress.IPv6Any.

System.Net.Sockets.ProtocolType protocolType

Optional. If specified the socket procotol

System.Boolean requireEvenPort

If true the method will only return successfully if it is able to bind on an even numbered port.

System.Boolean useDualMode

If true then IPv6 sockets will be created as dual mode IPv4/IPv6 on supporting systems.

Returns
Type Description
System.Net.Sockets.Socket

A bound socket if successful or throws an ApplicationException if unable to bind.

| Improve this Doc View Source

CreateBoundTcpSocket(Int32, IPAddress, Boolean, Boolean)

Attempts to create and bind a TCP socket. The socket is always created with the ExclusiveAddressUse socket option set to accommodate a Windows 10 .Net Core socket bug where the same port can be bound to two different sockets, see https://github.com/dotnet/runtime/issues/36618.

Declaration
public static Socket CreateBoundTcpSocket(int port, IPAddress bindAddress, bool requireEvenPort = false, bool useDualMode = true)
Parameters
Type Name Description
System.Int32 port

The port to attempt to bind on. Set to 0 to request the underlying OS to select a port.

System.Net.IPAddress bindAddress

Optional. If specified the TCP socket will attempt to bind using this specific address. If not specified the broadest possible address will be chosen. Either IPAddress.Any or IPAddress.IPv6Any.

System.Boolean requireEvenPort

If true the method will only return successfully if it is able to bind on an even numbered port.

System.Boolean useDualMode

If true then IPv6 sockets will be created as dual mode IPv4/IPv6 on supporting systems.

Returns
Type Description
System.Net.Sockets.Socket

A bound socket if successful or throws an ApplicationException if unable to bind.

| Improve this Doc View Source

CreateBoundUdpSocket(Int32, IPAddress, Boolean, Boolean)

Attempts to create and bind a UDP socket. The socket is always created with the ExclusiveAddressUse socket option set to accommodate a Windows 10 .Net Core socket bug where the same port can be bound to two different sockets, see https://github.com/dotnet/runtime/issues/36618.

Declaration
public static Socket CreateBoundUdpSocket(int port, IPAddress bindAddress, bool requireEvenPort = false, bool useDualMode = true)
Parameters
Type Name Description
System.Int32 port

The port to attempt to bind on. Set to 0 to request the underlying OS to select a port.

System.Net.IPAddress bindAddress

Optional. If specified the UDP socket will attempt to bind using this specific address. If not specified the broadest possible address will be chosen. Either IPAddress.Any or IPAddress.IPv6Any.

System.Boolean requireEvenPort

If true the method will only return successfully if it is able to bind on an even numbered port.

System.Boolean useDualMode

If true then IPv6 sockets will be created as dual mode IPv4/IPv6 on supporting systems.

Returns
Type Description
System.Net.Sockets.Socket

A bound socket if successful or throws an ApplicationException if unable to bind.

| Improve this Doc View Source

CreateRtpSocket(Boolean, IPAddress, Int32, PortRange, out Socket, out Socket)

Attempts to create and bind a new RTP UDP Socket, and optionally an control (RTCP), socket(s). The RTP and control sockets created are IPv4 and IPv6 dual mode sockets which means they can send and receive either IPv4 or IPv6 packets.

Declaration
public static void CreateRtpSocket(bool createControlSocket, IPAddress bindAddress, int bindPort, PortRange portRange, out Socket rtpSocket, out Socket controlSocket)
Parameters
Type Name Description
System.Boolean createControlSocket

True if a control (RTCP) socket should be created. Set to false if RTP and RTCP are being multiplexed on the same connection.

System.Net.IPAddress bindAddress

Optional. If null The RTP and control sockets will be created as IPv4 and IPv6 dual mode sockets which means they can send and receive either IPv4 or IPv6 packets. If the bind address is specified an attempt will be made to bind the RTP and optionally control listeners on it.

System.Int32 bindPort

Optional. If 0 the choice of port will be left up to the Operating System. If specified a single attempt will be made to bind on the port.

PortRange portRange

Optional. If non-null the choice of port will be left up to the PortRange. Multiple ports will be tried before giving up. The parameter bindPort is ignored.

System.Net.Sockets.Socket rtpSocket

An output parameter that will contain the allocated RTP socket.

System.Net.Sockets.Socket controlSocket

An output parameter that will contain the allocated control (RTCP) socket.

| Improve this Doc View Source

CreateRtpSocket(Boolean, ProtocolType, IPAddress, Int32, PortRange, Boolean, Boolean, out Socket, out Socket)

Attempts to create and bind a new RTP Socket with protocol, and optionally an control (RTCP), socket(s). The RTP and control sockets created are IPv4 and IPv6 dual mode sockets which means they can send and receive either IPv4 or IPv6 packets.

Declaration
public static void CreateRtpSocket(bool createControlSocket, ProtocolType protocolType, IPAddress bindAddress, int bindPort, PortRange portRange, bool requireEvenPort, bool useDualMode, out Socket rtpSocket, out Socket controlSocket)
Parameters
Type Name Description
System.Boolean createControlSocket

True if a control (RTCP) socket should be created. Set to false if RTP and RTCP are being multiplexed on the same connection.

System.Net.Sockets.ProtocolType protocolType

Procotol used by socket

System.Net.IPAddress bindAddress

Optional. If null The RTP and control sockets will be created as IPv4 and IPv6 dual mode sockets which means they can send and receive either IPv4 or IPv6 packets. If the bind address is specified an attempt will be made to bind the RTP and optionally control listeners on it.

System.Int32 bindPort

Optional. If 0 the choice of port will be left up to the Operating System. If specified a single attempt will be made to bind on the port.

PortRange portRange

Optional. If non-null the choice of port will be left up to the PortRange. Multiple ports will be tried before giving up. The parameter bindPort is ignored.

System.Boolean requireEvenPort
System.Boolean useDualMode
System.Net.Sockets.Socket rtpSocket

An output parameter that will contain the allocated RTP socket.

System.Net.Sockets.Socket controlSocket

An output parameter that will contain the allocated control (RTCP) socket.

| Improve this Doc View Source

GetLocalAddressesOnInterface(IPAddress, Boolean)

Determines the local IP address to use to connection a remote address and returns all the local addresses (IPv4 and IPv6) that are bound to the same interface. The main (and probably sole) use case for this method is gathering host candidates for a WebRTC ICE session. Rather than selecting ALL local IP addresses only those on the interface needed to connect to the destination are returned.

Declaration
public static List<IPAddress> GetLocalAddressesOnInterface(IPAddress destination, bool includeAllInterfaces = false)
Parameters
Type Name Description
System.Net.IPAddress destination

Optional. If not specified the interface that connects to the Internet will be used.

System.Boolean includeAllInterfaces

By default only the single interface that is used to connect to the destination address (or internet address if it's null) will be used to get the list of IP addresses. This default behaviour is to shield all local IP addresses being included in ICE candidates. In some circumstances, and after weighing up the security concerns, it's very useful to include all interfaces in when generating the address list. Setting this parameter to true will cause all interfaces to be used irrespective of the destination address.

Returns
Type Description
System.Collections.Generic.List<System.Net.IPAddress>

A list of local IP addresses on the identified interface(s).

| Improve this Doc View Source

GetLocalAddressForInternet()

Gets the default local address for this machine for communicating with the Internet.

Declaration
public static IPAddress GetLocalAddressForInternet()
Returns
Type Description
System.Net.IPAddress

The local address this machine should use for communicating with the Internet.

| Improve this Doc View Source

GetLocalAddressForRemote(IPAddress)

This method utilises the OS routing table to determine the local IP address to connect to a destination end point. It selects the correct local IP address, on a potentially multi-honed host, to communicate with a destination IP address. See https://github.com/sipsorcery/sipsorcery/issues/97 for elaboration.

Declaration
public static IPAddress GetLocalAddressForRemote(IPAddress destination)
Parameters
Type Name Description
System.Net.IPAddress destination

The remote destination to find a local IP address for.

Returns
Type Description
System.Net.IPAddress

The local IP address to use to connect to the remote end point.

| Improve this Doc View Source

GetLocalIPv6AddressForInternet()

Gets the default local IPv6 address for this machine for communicating with the Internet.

Declaration
public static IPAddress GetLocalIPv6AddressForInternet()
Returns
Type Description
System.Net.IPAddress

The local address this machine should use for communicating with the Internet.

| Improve this Doc View Source

HasActiveIPv6Address()

Check if the OS has an active IPv6 address configured.

Declaration
public static bool HasActiveIPv6Address()
Returns
Type Description
System.Boolean

Extension Methods

JSONWriter.ToJson(Object)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX