C# Class SnmpSharpNet.IpAddress

Inheritance: OctetString, IComparable, ICloneable
Exibir arquivo Open project: griffina/SnmpSharpNet Class Usage Examples

Public Properties

Property Type Description
ClassA int
ClassB int
ClassC int
ClassD int
ClassE int
InvalidClass int

Public Methods

Method Description
BuildMaskFromBits ( int bits ) : IpAddress

Build a subnet mask from bit count value

Clone ( ) : Object

Clone current object.

CompareTo ( object obj ) : int

Compare value against IPAddress, byte array, UInt32, IpAddress of OctetString class value.

Equals ( object obj ) : bool

Compare 2 IpAddress objects.

GetBroadcastAddress ( IpAddress mask ) : IpAddress

Returns broadcast address for the objects IP and supplied subnet mask. Subnet mask validity is not confirmed before performing the new value calculation so you should make sure parameter is a valid subnet mask by using IpAddress.IsValidMask method. Broadcast address is calculated by changing every bit in the subnet mask that is set to value 0 into 1 in the address value.

GetClass ( ) : int

Return network class of the IP address

GetHashCode ( ) : int

Return hash representing the value of this object

GetMaskBits ( ) : int

Returns number of subnet bits in the mask. Subnet bits are bits set to value 0 in the subnet mask.

GetSubnetAddress ( IpAddress mask ) : IpAddress

Return subnet address of the IP address in this object and supplied subnet mask

Increment ( UInt32 count ) : IpAddress

Increment IP address contained in the object by specific number and return the result as a new class.

Invert ( ) : IpAddress

Inverts IP address value. All 0s are converted to 1s and 1s to 0s

IpAddress ( ) : System

Constructs a default object with a length of zero. See the super class constructor for more details.

IpAddress ( IpAddress second ) : System

Copy constructor. Constructs a duplicate object based on the passed application string object.

IpAddress ( OctetString second ) : System

Copy constructor.

IpAddress ( System inetAddr ) : System

Constructor

Construct the IpAddress class from supplied IPAddress value.

IpAddress ( UInt32 inetAddr ) : System

Constructor

Initialize IpAddress class with the IP address value represented as 32-bit unsigned integer value

IpAddress ( byte data ) : System

Constructs an Application String with the passed data. The data is managed by the base class.

IpAddress ( string inetAddr ) : System

Constructs the class and initializes the value to the supplied IP address. See comments in IpAddress.Set(string) method for details.

IsIP ( string val ) : bool

Check if supplied string contains a valid IP address. Valid IP address contains 3 full stops (".") and 4 numeric values in range 0 to 255.

Written to address slow performance of IPAddress.TryParse

IsValidMask ( ) : bool

Checks if the value of the object is a valid subnet mask. Subnet mask is a value of consecutive bits with value of 1. If a bit is found with a value of 0 followed (immediately or anywhere else before the end of the value) by a 1, then subnet mask value is not valid.

NetworkMask ( ) : IpAddress

Returns network mask for the class value

Each IpAddress belongs to one of the 5 classes, A, B, C, D or E. D network class are multicast addresses and E is experimental class. Because D and E are not "real" network classes and as such don't have a network mask, only classes A, B and C will return a valid subnet mask. Classes D and E will return a null reference.

ReverseByteOrder ( uint val ) : uint

Reverse int value byte order. Static function in IPAddress class doesn't work the way I expected it (didn't troubleshoot) so here is another implementation. Reversing byte order is needed because network encoded IP address is presented in big-endian format. Intel based computers encode values in little-endian form so to perform numerical operations on received IP address values you will need to convert them from big to little-endian format. By the same token, if you wish to transmit data using IP address value calculated on the local system, you will need to convert it to big-endian prior to transmission.

Set ( IPAddress ipaddr ) : void

Set class value from the IPAddress argument

Set ( String value ) : void

Sets the class value to the IP address parsed from the string parameter.

Class value will be set with the parsed dotted decimal IP address in the parameter or if string parameter does not represent an IP address, DNS resolution will be performed. Note: DNS resolution is performed using System.Net.Dns.GetHostEntry(string) and can result in a longer then expected delay in this function. In applications where responsiveness is important, name resolution should be performed using async methods available and result passed to this method.

Set ( UInt32 ipvalue ) : void

Set class value from 32-bit unsigned integer value representation of the IP address value

ToString ( ) : System.String

Returns the application string as a dotted decimal represented IP address.

ToUInt32 ( ) : UInt32

Network byte order IP address

Convert internal byte array representation of the IP address into a network byte order (most significant byte first) unsigned integer value. To use the returned value in mathematical operations, you will need to change it to host byte order on little endian systems (all i386 compatible systems). To do that, call static method IpAddress.ReverseByteOrder().

decode ( byte buffer, int offset ) : int

Decode ASN.1 encoded IP address value.

Method Details

BuildMaskFromBits() public static method

Build a subnet mask from bit count value
public static BuildMaskFromBits ( int bits ) : IpAddress
bits int Number of subnet mask bits
return IpAddress

Clone() public method

Clone current object.
public Clone ( ) : Object
return System.Object

CompareTo() public method

Compare value against IPAddress, byte array, UInt32, IpAddress of OctetString class value.
public CompareTo ( object obj ) : int
obj object Type: or byte or or or
return int

Equals() public method

Compare 2 IpAddress objects.
public Equals ( object obj ) : bool
obj object object to compare against
return bool

GetBroadcastAddress() public method

Returns broadcast address for the objects IP and supplied subnet mask. Subnet mask validity is not confirmed before performing the new value calculation so you should make sure parameter is a valid subnet mask by using IpAddress.IsValidMask method. Broadcast address is calculated by changing every bit in the subnet mask that is set to value 0 into 1 in the address value.
public GetBroadcastAddress ( IpAddress mask ) : IpAddress
mask IpAddress Subnet mask to apply to the object
return IpAddress

GetClass() public method

Return network class of the IP address
public GetClass ( ) : int
return int

GetHashCode() public method

Return hash representing the value of this object
public GetHashCode ( ) : int
return int

GetMaskBits() public method

Returns number of subnet bits in the mask. Subnet bits are bits set to value 0 in the subnet mask.
public GetMaskBits ( ) : int
return int

GetSubnetAddress() public method

Return subnet address of the IP address in this object and supplied subnet mask
public GetSubnetAddress ( IpAddress mask ) : IpAddress
mask IpAddress Subnet mask
return IpAddress

Increment() public method

Increment IP address contained in the object by specific number and return the result as a new class.
public Increment ( UInt32 count ) : IpAddress
count System.UInt32 Number to increment IP address with
return IpAddress

Invert() public method

Inverts IP address value. All 0s are converted to 1s and 1s to 0s
public Invert ( ) : IpAddress
return IpAddress

IpAddress() public method

Constructs a default object with a length of zero. See the super class constructor for more details.
public IpAddress ( ) : System
return System

IpAddress() public method

Copy constructor. Constructs a duplicate object based on the passed application string object.
IpAddress argument is null
public IpAddress ( IpAddress second ) : System
second IpAddress The object to copy.
return System

IpAddress() public method

Copy constructor.
public IpAddress ( OctetString second ) : System
second OctetString The object to copy
return System

IpAddress() public method

Constructor
Construct the IpAddress class from supplied IPAddress value.
public IpAddress ( System inetAddr ) : System
inetAddr System IP Address to use to initialize the object.
return System

IpAddress() public method

Constructor
Initialize IpAddress class with the IP address value represented as 32-bit unsigned integer value
public IpAddress ( UInt32 inetAddr ) : System
inetAddr System.UInt32 32-bit unsigned integer representation of an IP Address
return System

IpAddress() public method

Constructs an Application String with the passed data. The data is managed by the base class.
public IpAddress ( byte data ) : System
data byte The application string to manage (UTF-8) ///
return System

IpAddress() public method

Constructs the class and initializes the value to the supplied IP address. See comments in IpAddress.Set(string) method for details.
public IpAddress ( string inetAddr ) : System
inetAddr string IP address encoded as a string or host name
return System

IsIP() public static method

Check if supplied string contains a valid IP address. Valid IP address contains 3 full stops (".") and 4 numeric values in range 0 to 255.
Written to address slow performance of IPAddress.TryParse
public static IsIP ( string val ) : bool
val string String value
return bool

IsValidMask() public method

Checks if the value of the object is a valid subnet mask. Subnet mask is a value of consecutive bits with value of 1. If a bit is found with a value of 0 followed (immediately or anywhere else before the end of the value) by a 1, then subnet mask value is not valid.
public IsValidMask ( ) : bool
return bool

NetworkMask() public method

Returns network mask for the class value
Each IpAddress belongs to one of the 5 classes, A, B, C, D or E. D network class are multicast addresses and E is experimental class. Because D and E are not "real" network classes and as such don't have a network mask, only classes A, B and C will return a valid subnet mask. Classes D and E will return a null reference.
public NetworkMask ( ) : IpAddress
return IpAddress

ReverseByteOrder() public static method

Reverse int value byte order. Static function in IPAddress class doesn't work the way I expected it (didn't troubleshoot) so here is another implementation. Reversing byte order is needed because network encoded IP address is presented in big-endian format. Intel based computers encode values in little-endian form so to perform numerical operations on received IP address values you will need to convert them from big to little-endian format. By the same token, if you wish to transmit data using IP address value calculated on the local system, you will need to convert it to big-endian prior to transmission.
public static ReverseByteOrder ( uint val ) : uint
val uint Integer value to reverse
return uint

Set() public method

Set class value from the IPAddress argument
public Set ( IPAddress ipaddr ) : void
ipaddr System.Net.IPAddress Type: class instance
return void

Set() public method

Sets the class value to the IP address parsed from the string parameter.
Class value will be set with the parsed dotted decimal IP address in the parameter or if string parameter does not represent an IP address, DNS resolution will be performed. Note: DNS resolution is performed using System.Net.Dns.GetHostEntry(string) and can result in a longer then expected delay in this function. In applications where responsiveness is important, name resolution should be performed using async methods available and result passed to this method.
Thrown when DNS resolution of the parameter value has failed.
public Set ( String value ) : void
value String IP address encoded as a string or host name
return void

Set() public method

Set class value from 32-bit unsigned integer value representation of the IP address value
public Set ( UInt32 ipvalue ) : void
ipvalue System.UInt32 IP address value as 32-bit unsigned integer value
return void

ToString() public method

Returns the application string as a dotted decimal represented IP address.
public ToString ( ) : System.String
return System.String

ToUInt32() public method

Network byte order IP address
Convert internal byte array representation of the IP address into a network byte order (most significant byte first) unsigned integer value. To use the returned value in mathematical operations, you will need to change it to host byte order on little endian systems (all i386 compatible systems). To do that, call static method IpAddress.ReverseByteOrder().
public ToUInt32 ( ) : UInt32
return System.UInt32

decode() public method

Decode ASN.1 encoded IP address value.
Parsed data length is not 4 bytes long Parsed data is not in IpAddress format
public decode ( byte buffer, int offset ) : int
buffer byte BER encoded data buffer
offset int Offset in the array to start parsing from
return int

Property Details

ClassA public_oe static_oe property

Class A IP address
public static int ClassA
return int

ClassB public_oe static_oe property

Class B IP address
public static int ClassB
return int

ClassC public_oe static_oe property

Class C IP address
public static int ClassC
return int

ClassD public_oe static_oe property

Class D IP address
public static int ClassD
return int

ClassE public_oe static_oe property

Class E IP address
public static int ClassE
return int

InvalidClass public_oe static_oe property

Invalid IP address class
public static int InvalidClass
return int