namespace System.Net
{
///
/// Provides extension methods for es.
///
public static class IPAddressExtensions
{
///
/// Increments the by one and returns a new instance.
///
/// The to increment.
public static IPAddress Increment(this IPAddress address)
{
byte[] bytes = address.GetAddressBytes();
int bytePos = bytes.Length - 1;
while (bytes[bytePos] == byte.MaxValue)
{
bytes[bytePos] = 0;
bytePos--;
if (bytePos < 0)
return new IPAddress(bytes);
}
bytes[bytePos]++;
return new IPAddress(bytes);
}
///
/// Decrements the by one and returns a new instance.
///
/// The to decrement.
public static IPAddress Decrement(this IPAddress address)
{
byte[] bytes = address.GetAddressBytes();
int bytePos = bytes.Length - 1;
while (bytes[bytePos] == 0)
{
bytes[bytePos] = byte.MaxValue;
bytePos--;
if (bytePos < 0)
return new IPAddress(bytes);
}
bytes[bytePos]--;
return new IPAddress(bytes);
}
}
}