/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include "IPAddressV6.h"
+#include <folly/IPAddressV6.h>
#include <ostream>
#include <string>
static inline void unpackInto(const unsigned char* src,
uint16_t* dest,
size_t count) {
- for (int i = 0, hi = 1, lo = 0; i < count; i++) {
+ for (size_t i = 0, hi = 1, lo = 0; i < count; i++) {
dest[i] = unpack(src[hi], src[lo]);
hi += 2;
lo += 2;
// public
bool IPAddressV6::isLoopback() const {
- const unsigned char* by = bytes();
- for (int i = 0; i < 15; i++) {
- if (by[i] != 0x00) {
- return false;
- }
+ // Check if v4 mapped is loopback
+ if (isIPv4Mapped() && createIPv4().isLoopback()) {
+ return true;
}
- return (by[15] == 0x01);
+ auto socka = toSockAddr();
+ return IN6_IS_ADDR_LOOPBACK(&socka.sin6_addr);
}
bool IPAddressV6::isRoutable() const {
// public
bool IPAddressV6::isPrivate() const {
+ // Check if mapped is private
+ if (isIPv4Mapped() && createIPv4().isPrivate()) {
+ return true;
+ }
return isLoopback() || inBinarySubnet({{0xfc, 0x00}}, 7);
}
+// public
bool IPAddressV6::isLinkLocal() const {
return inBinarySubnet({{0xfe, 0x80}}, 10);
}