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.

Namespace: SnmpSharpNet
Assembly: SnmpSharpNet (in SnmpSharpNet.dll) Version: 0.9.1.0 (0.9.1)

Syntax

C#
public static uint ReverseByteOrder(
	uint val
)
Visual Basic
Public Shared Function ReverseByteOrder ( _
	val As UInteger _
) As UInteger
Visual C++
public:
static unsigned int ReverseByteOrder(
	unsigned int val
)

Parameters

val
Type: System..::..UInt32
Integer value to reverse

Return Value

Reversed integer value

Examples

Here is an example that demonstrates what this method does:
CopyC#
IpAddress test = new IpAddress(new byte[] { 10, 20, 30, 40 }); // Example IP: 10.20.30.40
UInt32 testValue = test.ToUInt32();
UInt32 reverseValue = IpAddress.ReverseByteOrder(testValue);
IpAddress newTest = new IpAddress(reverseValue);
Console.WriteLine("New IP: {0}", newTest.ToString()); // Output "New IP: 40.30.20.10"        ///

See Also