Class Mapping
Represents a port forwarding entry in the NAT translation table.
Inherited Members
Namespace: SharpOpenNat
Assembly: SharpOpenNat.dll
Syntax
public class Mapping
Constructors
| Edit this page View SourceMapping(Protocol, int, int)
Initializes a new instance of the Mapping class.
Declaration
public Mapping(Protocol protocol, int privatePort, int publicPort)
Parameters
Type | Name | Description |
---|---|---|
Protocol | protocol | The protocol. |
int | privatePort | The private port. |
int | publicPort | The public port. |
Remarks
This constructor initializes a Permanent mapping. The description by default is "SharpOpenNat"
Mapping(Protocol, int, int, int, string)
Initializes a new instance of the Mapping class.
Declaration
public Mapping(Protocol protocol, int privatePort, int publicPort, int lifetime, string description)
Parameters
Type | Name | Description |
---|---|---|
Protocol | protocol | The protocol. |
int | privatePort | The private port. |
int | publicPort | The public port. |
int | lifetime | The lifetime in seconds. |
string | description | The description. |
Mapping(Protocol, int, int, string)
Initializes a new instance of the Mapping class.
Declaration
public Mapping(Protocol protocol, int privatePort, int publicPort, string description)
Parameters
Type | Name | Description |
---|---|---|
Protocol | protocol | The protocol. |
int | privatePort | The private port. |
int | publicPort | The public port. |
string | description | The description. |
Remarks
This constructor initializes a Permanent mapping.
Mapping(Protocol, IPAddress, int, int, int, string)
Initializes a new instance of the Mapping class.
Declaration
public Mapping(Protocol protocol, IPAddress privateIP, int privatePort, int publicPort, int lifetime, string description)
Parameters
Type | Name | Description |
---|---|---|
Protocol | protocol | The protocol. |
IPAddress | privateIP | The private ip. |
int | privatePort | The private port. |
int | publicPort | The public port. |
int | lifetime | The lifetime in seconds. |
string | description | The description. |
Properties
| Edit this page View SourceDescription
Gets the mapping's description. It is the value stored in the NewPortMappingDescription parameter. The NewPortMappingDescription parameter is a human readable string that describes the connection. It is used in sorme web interfaces of routers so the user can see which program is using what port.
Declaration
public string Description { get; }
Property Value
Type | Description |
---|---|
string |
Expiration
Gets the expiration. The property value is calculated using Lifetime property.
Declaration
public DateTime Expiration { get; }
Property Value
Type | Description |
---|---|
DateTime |
Lifetime
Gets the lifetime in seconds. The Lifetime parameter tells the router how long the portmapping should be active. Since most programs don't know this in advance, it is often set to 0, which means 'unlimited' or 'permanent'.
Declaration
public int Lifetime { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
All portmappings are release automatically as part of the shutdown process. Permanent portmappings will not be released if the process ends anormally. Since most programs don't know the lifetime in advance, SharpOpenNat renew all the portmappings (except the permanents) before they expires. So, developers have to close explicitly those portmappings they don't want to remain open for the session.
LifetimeType
Gets the Lifetime of the mapping
Declaration
public MappingLifetime LifetimeType { get; }
Property Value
Type | Description |
---|---|
MappingLifetime |
PrivateIP
Gets the private ip.
Declaration
public IPAddress PrivateIP { get; }
Property Value
Type | Description |
---|---|
IPAddress |
PrivatePort
The PrivatePort parameter specifies the port on a client machine to which all traffic coming in on PublicPort for the protocol specified by Protocol should be forwarded to.
Declaration
public int PrivatePort { get; }
Property Value
Type | Description |
---|---|
int |
Protocol
Gets the protocol.
Declaration
public Protocol Protocol { get; }
Property Value
Type | Description |
---|---|
Protocol |
PublicIP
Gets the public ip.
Declaration
public IPAddress PublicIP { get; }
Property Value
Type | Description |
---|---|
IPAddress |
PublicPort
Gets the external (visible) port number. It is the value stored in the NewExternalPort parameter . The NewExternalPort parameter is used to specify the TCP or UDP port on the WAN side of the router which should be forwarded.
Declaration
public int PublicPort { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceEquals(object?)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
| Edit this page View SourceGetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
| Edit this page View SourceIsExpired()
Determines whether this instance is expired.
Declaration
public bool IsExpired()
Returns
Type | Description |
---|---|
bool |
Remarks
Permanent mappings never expires.
ToString()
Returns a string that represents this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents this instance. |