void test_method_hostmask() { var prefix = Prefix32.create(8).unwrap(); Xunit.Assert.Equal("0.255.255.255", IpV4.from_u32((UInt32)prefix.host_mask(), 0).unwrap().to_s()); }
public override int GetHashCode() { int hash = 1; if (AddressType != global::AcFunDanmu.AccessPoint.Types.AddressType.KIpv4) { hash ^= AddressType.GetHashCode(); } if (Port != 0) { hash ^= Port.GetHashCode(); } if (IpV4 != 0) { hash ^= IpV4.GetHashCode(); } if (IpV6.Length != 0) { hash ^= IpV6.GetHashCode(); } if (Domain.Length != 0) { hash ^= Domain.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override bool Equals(object o) { if (((Ip)o).InetKind == InetKind) { if (InetKind == InetKind.V4) { if (IpV4 == null && ((Ip)o).IpV4 == null) { return(true); } return(IpV4 != null && !IpV4.Where((t, i) => ((Ip)o).IpV4[i] != t).Any()); } if (IpV6 == null && ((Ip)o).IpV6 == null) { return(true); } if (ScopeId != ((Ip)o).ScopeId) { return(false); } return(IpV6 != null && !IpV6.Where((t, i) => ((Ip)o).IpV6[i] != t).Any()); } return(false); }
void test_classmethod_parse_classful() { foreach (var kp in setup().classful) { var ip = kp.Key; var prefix = kp.Value; var res = IpV4.parse_classful(ip).unwrap(); Assert.Equal(prefix, res.prefix.num); Assert.Equal(string.Format("{0}/{1}", ip, prefix), res.to_string()); } Assert.True(IpV4.parse_classful("192.168.256.257").isErr()); }
void test_classmethod_parse_u32() { foreach (var kp in setup().decimal_values) { var addr = kp.Key; var value = kp.Value; var ip = IpV4.from_u32(value, 32).unwrap(); var splitted = addr.Split(new string[] { "/" }, StringSplitOptions.None); var ip2 = ip.change_prefix(uint.Parse(splitted[1])).unwrap(); Assert.Equal(ip2.to_string(), addr); } }
//ホストバイトオーダのデータで初期化する public Ip(uint ip) { Init(InetKind.V4);//デフォルト値での初期化 byte[] tmp = BitConverter.GetBytes(ip); for (int i = 0; i < 4; i++) { IpV4[i] = tmp[3 - i]; } if (IpV4.Max() == 0) { Any = true; } }
static IPv4Test setup() { var ipv4t = new IPv4Test( new List <String> { "10.0.0.256", "10.0.0.0.0" }, new List <String> { "10.0.0.1-254", "10.0.1-254.0", "10.1-254.0.0" }, IpV4.create("172.16.10.1/24").unwrap(), IpV4.create("172.16.10.0/24").unwrap(), IpV4.create("10.0.0.1/8").unwrap(), IpV4.create("172.16.0.1/16").unwrap(), IpV4.create("192.168.0.1/24").unwrap()); ipv4t.valid_ipv4.Add("9.9/17", new IPv4Prefix( "9.0.0.9", 17 )); ipv4t.valid_ipv4.Add("100.1.100", new IPv4Prefix( "100.1.0.100", 32 )); ipv4t.valid_ipv4.Add("0.0.0.0/0", new IPv4Prefix( "0.0.0.0", 0 )); ipv4t.valid_ipv4.Add("10.0.0.0", new IPv4Prefix( "10.0.0.0", 32 )); ipv4t.valid_ipv4.Add("10.0.0.1", new IPv4Prefix( "10.0.0.1", 32 )); ipv4t.valid_ipv4.Add("10.0.0.1/24", new IPv4Prefix( "10.0.0.1", 24 )); ipv4t.valid_ipv4.Add("10.0.0.9/255.255.255.0", new IPv4Prefix( "10.0.0.9", 24 )); ipv4t.netmask_values.Add("0.0.0.0/0", "0.0.0.0"); ipv4t.netmask_values.Add("10.0.0.0/8", "255.0.0.0"); ipv4t.netmask_values.Add("172.16.0.0/16", "255.255.0.0"); ipv4t.netmask_values.Add("192.168.0.0/24", "255.255.255.0"); ipv4t.netmask_values.Add("192.168.100.4/30", "255.255.255.252"); ipv4t.decimal_values.Add("0.0.0.0/0", 0); ipv4t.decimal_values.Add("10.0.0.0/8", 167772160); ipv4t.decimal_values.Add("172.16.0.0/16", 2886729728); ipv4t.decimal_values.Add("192.168.0.0/24", 3232235520); ipv4t.decimal_values.Add("192.168.100.4/30", 3232261124); ipv4t.ip = IPAddress.parse("172.16.10.1/24").unwrap(); ipv4t.network = IPAddress.parse("172.16.10.0/24").unwrap(); ipv4t.broadcast.Add("10.0.0.0/8", "10.255.255.255/8"); ipv4t.broadcast.Add("172.16.0.0/16", "172.16.255.255/16"); ipv4t.broadcast.Add("192.168.0.0/24", "192.168.0.255/24"); ipv4t.broadcast.Add("192.168.100.4/30", "192.168.100.7/30"); ipv4t.networks.Add("10.5.4.3/8", "10.0.0.0/8"); ipv4t.networks.Add("172.16.5.4/16", "172.16.0.0/16"); ipv4t.networks.Add("192.168.4.3/24", "192.168.4.0/24"); ipv4t.networks.Add("192.168.100.5/30", "192.168.100.4/30"); ipv4t.class_a = IPAddress.parse("10.0.0.1/8").unwrap(); ipv4t.class_b = IPAddress.parse("172.16.0.1/16").unwrap(); ipv4t.class_c = IPAddress.parse("192.168.0.1/24").unwrap(); ipv4t.classful.Add("10.1.1.1", 8); ipv4t.classful.Add("150.1.1.1", 16); ipv4t.classful.Add("200.1.1.1", 24); return(ipv4t); }
void test_method_c() { Assert.Equal(true, IpV4.is_class_c(setup().class_c)); Assert.Equal(false, IpV4.is_class_c(setup().class_a)); Assert.Equal(false, IpV4.is_class_c(setup().class_b)); }
//ネットワークバイトオーダ public byte[] NetBytes() { CheckInitialise(); return(InetKind == InetKind.V4 ? IpV4.ToArray() : IpV6.ToArray()); }