move MemoryMapping, Shell, ThreadId, ThreadName, and VersionCheck to system/
[folly.git] / folly / IPAddressV6.cpp
index 70f5c883c2b5a238dca7d190822c2d9d7527a7fc..be909315f147b2c35ecb970062f4d4bfd179e25e 100644 (file)
@@ -31,8 +31,8 @@
 // Because of the massive pain that is libnl, this can't go into the socket
 // portability header as you can't include <linux/if.h> and <net/if.h> in
 // the same translation unit without getting errors -_-...
-#include <iphlpapi.h>
-#include <ntddndis.h>
+#include <iphlpapi.h> // @manual
+#include <ntddndis.h> // @manual
 
 // Alias the max size of an interface name to what posix expects.
 #define IFNAMSIZ IF_NAMESIZE
@@ -138,20 +138,23 @@ IPAddressV6::AddressStorage::AddressStorage(MacAddress mac) {
 
 Optional<MacAddress> IPAddressV6::getMacAddressFromLinkLocal() const {
   // Returned MacAddress must be constructed from a link-local IPv6 address.
-  if (!(addr_.bytes_[0] == 0xfe && addr_.bytes_[1] == 0x80 &&
-        addr_.bytes_[2] == 0x00 && addr_.bytes_[3] == 0x00 &&
-        addr_.bytes_[4] == 0x00 && addr_.bytes_[5] == 0x00 &&
-        addr_.bytes_[6] == 0x00 && addr_.bytes_[7] == 0x00 &&
-        addr_.bytes_[11] == 0xff && addr_.bytes_[12] == 0xfe)) {
+  if (!isLinkLocal()) {
     return folly::none;
   }
-  // The link-local address uses modified EUI-64 format,
+  return getMacAddressFromEUI64();
+}
+
+Optional<MacAddress> IPAddressV6::getMacAddressFromEUI64() const {
+  if (!(addr_.bytes_[11] == 0xff && addr_.bytes_[12] == 0xfe)) {
+    return folly::none;
+  }
+  // The auto configured address uses modified EUI-64 format,
   // See RFC 4291 sections 2.5.1, 2.5.6, and Appendix A
   std::array<uint8_t, MacAddress::SIZE> bytes;
-  // Step 1: first 8 bytes are fe:80:00:00:00:00:00:00, and can be stripped
+  // Step 1: first 8 bytes are network prefix, and can be stripped
   // Step 2: invert the universal/local (U/L) flag (bit 7)
   bytes[0] = addr_.bytes_[8] ^ 0x02;
-  // Step 3: copy thhese bytes are they are
+  // Step 3: copy these bytes as they are
   bytes[1] = addr_.bytes_[9];
   bytes[2] = addr_.bytes_[10];
   // Step 4: strip bytes (0xfffe), which are bytes_[11] and bytes_[12]