예제 #1
0
 /// Obtain the netmask that corresponds to the address, based on its address
 /// class.
 static address_v4 netmask(const address_v4& addr)
 {
   if (addr.is_class_a())
     return address_v4(0xFF000000);
   if (addr.is_class_b())
     return address_v4(0xFFFF0000);
   if (addr.is_class_c())
     return address_v4(0xFFFFFF00);
   return address_v4(0xFFFFFFFF);
 }
예제 #2
0
 /// Create an IPv4-compatible IPv6 address.
 static address_v6 v4_compatible(const address_v4& addr)
 {
   address_v4::bytes_type v4_bytes = addr.to_bytes();
   bytes_type v6_bytes = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     v4_bytes[0], v4_bytes[1], v4_bytes[2], v4_bytes[3] } };
   return address_v6(v6_bytes);
 }
예제 #3
0
 /// Create an IPv4-mapped IPv6 address.
 static address_v6 v4_mapped(const address_v4& addr)
 {
   address_v4::bytes_type v4_bytes = addr.to_bytes();
   bytes_type v6_bytes = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF,
     v4_bytes[0], v4_bytes[1], v4_bytes[2], v4_bytes[3] } };
   return address_v6(v6_bytes);
 }
 /// Compare addresses for ordering.
 friend bool operator>=(const address_v4& a1, const address_v4& a2)
 {
   return a1.to_ulong() >= a2.to_ulong();
 }
 /// Compare addresses for ordering.
 friend bool operator<=(const address_v4& a1, const address_v4& a2)
 {
   return a1.to_uint() <= a2.to_uint();
 }
예제 #6
0
 /// Obtain an address object that represents the broadcast address that
 /// corresponds to the specified address and netmask.
 static address_v4 broadcast(const address_v4& addr, const address_v4& mask)
 {
   return address_v4(addr.to_ulong() | ~mask.to_ulong());
 }