Class IPSocket
Inheritance
Inherited Members
Namespace: SIPSorcery.Sys
Assembly: SIPSorcery.dll
Syntax
public class IPSocket
Fields
| Improve this Doc View SourceMaxPort
Specifies the maximum acceptable value for the System.Net.IPEndPoint Port property.
Declaration
public const int MaxPort = 65535
Field Value
Type | Description |
---|---|
System.Int32 |
MinPort
Specifies the minimum acceptable value for the System.Net.IPEndPoint Port property.
Declaration
public const int MinPort = 0
Field Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceGetIPEndPoint(String)
Returns an IPv4 end point from a socket address in 10.0.0.1:5060 format.
Declaration
public static IPEndPoint GetIPEndPoint(string IPSocket)
Parameters
Type | Name | Description |
---|---|---|
System.String | IPSocket |
Returns
Type | Description |
---|---|
System.Net.IPEndPoint |
GetSocketString(IPEndPoint)
This code is based on the IPEndPoint.ToString method in the dotnet source code at https://github.com/dotnet/corefx/blob/master/src/System.Net.Primitives/src/System/Net/IPEndPoint.cs. If/when that feature makes it into .NET Standard this method can be replaced.
Declaration
public static string GetSocketString(IPEndPoint endPoint)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPEndPoint | endPoint |
Returns
Type | Description |
---|---|
System.String |
IsIPAddress(String)
(convenience method) check if string can be parsed as IPAddress
Declaration
public static bool IsIPAddress(string socket)
Parameters
Type | Name | Description |
---|---|---|
System.String | socket | string to check |
Returns
Type | Description |
---|---|
System.Boolean | true/false |
IsPrivateAddress(String)
Checks the Contact SIP URI host and if it is recognised as a private address it is replaced with the socket the SIP message was received on.
Private address space blocks RFC 1597. 10.0.0.0 - 10.255.255.255 172.16.0.0 - 172.31.255.255 192.168.0.0 - 192.168.255.255
Declaration
public static bool IsPrivateAddress(string host)
Parameters
Type | Name | Description |
---|---|---|
System.String | host |
Returns
Type | Description |
---|---|
System.Boolean |
Parse(String, Int32)
Declaration
public static IPEndPoint Parse(string endpointstring, int defaultport = -1)
Parameters
Type | Name | Description |
---|---|---|
System.String | endpointstring | |
System.Int32 | defaultport |
Returns
Type | Description |
---|---|
System.Net.IPEndPoint |
Parse(String, out String, out Int32)
Check if endpointstring
contains a hostname or ip-address and ip-port
accepts IPv4 and IPv6 and IPv6 mapped IPv4 addresses
return detected values in host
and port
adapted from: http://stackoverflow.com/questions/2727609/best-way-to-create-ipendpoint-from-string
Declaration
public static bool Parse(string endpointstring, out string host, out int port)
Parameters
Type | Name | Description |
---|---|---|
System.String | endpointstring | string to check |
System.String | host | host-portion of |
System.Int32 | port | port-portion of |
Returns
Type | Description |
---|---|
System.Boolean | true if host-portion of endpoint string is valid ip-address |
Remarks
rj2: I had the requirement of parsing an IPEndpoint with IPv6, v4 and hostnames and getting them as string and int
Exceptions
Type | Condition |
---|---|
System.ArgumentException | if |
System.FormatException | if host looks like ip-address but can't be parsed |
ParseHostFromSocket(String)
Declaration
public static string ParseHostFromSocket(string socket)
Parameters
Type | Name | Description |
---|---|---|
System.String | socket |
Returns
Type | Description |
---|---|
System.String |
ParsePortFromSocket(String)
For IPv6 addresses with port the string format is of the form: [2a02:8084:6981:7880:54a9:d238:b2ee:ceb]:6060 Without a port the form is: 2a02:8084:6981:7880:54a9:d238:b2ee:ceb
Declaration
public static int ParsePortFromSocket(string socket)
Parameters
Type | Name | Description |
---|---|---|
System.String | socket | The socket string to check |
Returns
Type | Description |
---|---|
System.Int32 | The socket string's explicit port number or 0 if it does not have one. |
ParseSocketString(String)
Declaration
public static IPEndPoint ParseSocketString(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s |
Returns
Type | Description |
---|---|
System.Net.IPEndPoint |
TryParseIPEndPoint(String, out IPEndPoint)
This code is based on the IPEndPoint.TryParse method in the dotnet source code at https://github.com/dotnet/corefx/blob/master/src/System.Net.Primitives/src/System/Net/IPEndPoint.cs. If/when that feature makes it into .NET Standard this method can be replaced.
Declaration
public static bool TryParseIPEndPoint(string s, out IPEndPoint result)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The end point string to parse. |
System.Net.IPEndPoint | result | If the parse is successful this output parameter will contain the IPv4 or IPv6 end point. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the string could be successfully parsed as an IPv4 or IPv6 end point. False if not. |