Class IPSocket
Class containing various utility functions for sockets.
Inherited Members
Namespace: SipLib.Core
Assembly: SipLib.dll
Syntax
public class IPSocket
Fields
| Edit this page View SourceMaxPort
Specifies the maximum acceptable value for the IPEndPoint Port property.
Declaration
public const int MaxPort = 65535
Field Value
Type | Description |
---|---|
int |
MinPort
Specifies the minimum acceptable value for the IPEndPoint Port property.
Declaration
public const int MinPort = 0
Field Value
Type | Description |
---|---|
int |
Methods
| Edit this page 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 |
---|---|---|
string | IPSocket |
Returns
Type | Description |
---|---|
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 |
---|---|---|
IPEndPoint | endPoint |
Returns
Type | Description |
---|---|
string |
IsIPAddress(string)
(convenience method) check if string can be parsed as IPAddress
Declaration
public static bool IsIPAddress(string socket)
Parameters
Type | Name | Description |
---|---|---|
string | socket | string to check |
Returns
Type | Description |
---|---|
bool | 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 |
---|---|---|
string | host |
Returns
Type | Description |
---|---|
bool |
Parse(string, int)
Parses an endpoint string into an IPEndPoint
Declaration
public static IPEndPoint Parse(string endpointstring, int defaultport = -1)
Parameters
Type | Name | Description |
---|---|---|
string | endpointstring | |
int | defaultport |
Returns
Type | Description |
---|---|
IPEndPoint |
Parse(string, out string, out int)
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 |
---|---|---|
string | endpointstring | string to check |
string | host | host-portion of |
int | port | port-portion of |
Returns
Type | Description |
---|---|
bool | 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 |
---|---|
ArgumentException | if |
FormatException | if host looks like ip-address but can't be parsed |
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 |
---|---|---|
string | socket | The socket string to check |
Returns
Type | Description |
---|---|
int | The socket string's explicit port number or 0 if it does not have one. |
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 |
---|---|---|
string | s | The end point string to parse. |
IPEndPoint | result | If the parse is successful this output parameter will contain the IPv4 or IPv6 end point. |
Returns
Type | Description |
---|---|
bool | Returns true if the string could be successfully parsed as an IPv4 or IPv6 end point. False if not. |