Fix resplit | batch
[folly.git] / folly / IPAddress.h
index e147c10d7bc599970e9401f70ee975f90edfea38..797ab57c744c3b92d2edbc4b44655eb9fc54c054 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -24,6 +24,7 @@
 
 #include <boost/operators.hpp>
 
+#include <folly/Conv.h>
 #include <folly/Format.h>
 #include <folly/Range.h>
 #include <folly/IPAddressException.h>
@@ -98,7 +99,7 @@ class IPAddress : boost::totally_ordered<IPAddress> {
    * @return string representing the netblock
    */
   static std::string networkToString(const CIDRNetwork& network) {
-    return network.first.str() + "/" + std::to_string(network.second);
+    return network.first.str() + "/" + folly::to<std::string>(network.second);
   }
 
   /**
@@ -206,6 +207,7 @@ class IPAddress : boost::totally_ordered<IPAddress> {
       sockaddr_in6 *sin = reinterpret_cast<sockaddr_in6*>(dest);
       sin->sin6_addr = asV6().toAddr();
       sin->sin6_port = port;
+      sin->sin6_scope_id = asV6().getScopeId();
       return sizeof(*sin);
     } else {
       throw InvalidAddressFamilyException(family());
@@ -255,7 +257,7 @@ class IPAddress : boost::totally_ordered<IPAddress> {
   bool empty() const { return (family_ == AF_UNSPEC); }
 
   // @return true if address is initialized
-  explicit operator bool() { return !empty(); }
+  explicit operator bool() const { return !empty(); }
 
   // @return true if this is an IPAddressV4 instance
   bool isV4() const { return (family_ == AF_INET); }
@@ -316,6 +318,12 @@ class IPAddress : boost::totally_ordered<IPAddress> {
                   : asV6().isLoopback();
   }
 
+  // Return true if the address qualifies as link local
+  bool isLinkLocal() const {
+    return isV4() ? asV4().isLinkLocal()
+                  : asV6().isLinkLocal();
+  }
+
   // Return true if the address qualifies as broadcast.
   bool isLinkLocalBroadcast() const {
     return isV4() ? asV4().isLinkLocalBroadcast()