Add Minimalistic IPv4 class
ln.build - build0.l--n.de build job pending
Details
ln.build - build0.l--n.de build job pending
Details
parent
7510e7296a
commit
db015ed6db
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ln.type
|
||||||
|
{
|
||||||
|
public class IPv4
|
||||||
|
{
|
||||||
|
public static readonly IPv4 ANY = new IPv4();
|
||||||
|
|
||||||
|
private UInt32 _ip;
|
||||||
|
private IPv4()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public IPv4(UInt32 ip)
|
||||||
|
{
|
||||||
|
_ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPv4(byte[] ipbytes)
|
||||||
|
{
|
||||||
|
_ip = BitConverter.ToUInt32(ipbytes, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] ToBytes => BitConverter.GetBytes(_ip);
|
||||||
|
|
||||||
|
public override bool Equals(Object obj) => (obj is IPv4 other) && _ip == other._ip;
|
||||||
|
public override int GetHashCode() => (int)_ip;
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
byte[] ipbytes = ToBytes;
|
||||||
|
return string.Format("{0}.{1}.{2}.{3}", ipbytes[3], ipbytes[2], ipbytes[1], ipbytes[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IPv4 operator ++(IPv4 ip) => new IPv4(ip._ip + 1);
|
||||||
|
public static IPv4 operator --(IPv4 ip) => new IPv4(ip._ip - 1);
|
||||||
|
|
||||||
|
public static IPv4 operator +(IPv4 ip, int n) => new IPv4((uint)(ip._ip + n));
|
||||||
|
public static IPv4 operator -(IPv4 ip, int n) => new IPv4((uint)(ip._ip - n));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
<Company>l--n.de</Company>
|
<Company>l--n.de</Company>
|
||||||
<AssemblyVersion>0.0.1.0</AssemblyVersion>
|
<AssemblyVersion>0.0.1.0</AssemblyVersion>
|
||||||
<FileVersion>0.0.1.0</FileVersion>
|
<FileVersion>0.0.1.0</FileVersion>
|
||||||
|
<PackageVersion>0.1.8-dev</PackageVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue