diff --git a/ln.type/IPv4.cs b/ln.type/IPv4.cs new file mode 100644 index 0000000..b6182b8 --- /dev/null +++ b/ln.type/IPv4.cs @@ -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)); + + + + } +} \ No newline at end of file diff --git a/ln.type/ln.type.csproj b/ln.type/ln.type.csproj index 0a1e993..239a870 100644 --- a/ln.type/ln.type.csproj +++ b/ln.type/ln.type.csproj @@ -8,6 +8,7 @@ l--n.de 0.0.1.0 0.0.1.0 + 0.1.8-dev