// IsLoopback reports whether ip is a loopback address. public static bool IsLoopback(this IP ip) { { var ip4 = ip.To4(); if (ip4 != null) { return(ip4[0L] == 127L); } } return(ip.Equal(IPv6loopback)); }
// IsGlobalUnicast reports whether ip is a global unicast // address. // // The identification of global unicast addresses uses address type // identification as defined in RFC 1122, RFC 4632 and RFC 4291 with // the exception of IPv4 directed broadcast addresses. // It returns true even if ip is in IPv4 private address space or // local IPv6 unicast address space. public static bool IsGlobalUnicast(this IP ip) { return((len(ip) == IPv4len || len(ip) == IPv6len) && !ip.Equal(IPv4bcast) && !ip.IsUnspecified() && !ip.IsLoopback() && !ip.IsMulticast() && !ip.IsLinkLocalUnicast()); }
// IsUnspecified reports whether ip is an unspecified address, either // the IPv4 address "0.0.0.0" or the IPv6 address "::". public static bool IsUnspecified(this IP ip) { return(ip.Equal(IPv4zero) || ip.Equal(IPv6unspecified)); }