save/restore request context in future
[folly.git] / folly / IPAddress.h
index 46c096578dee6ae2b2ac47c09daa88d36b019a92..b1c474a602b273da339be1709af5bf6c297dd631 100644 (file)
@@ -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());
@@ -251,6 +253,12 @@ class IPAddress : boost::totally_ordered<IPAddress> {
     return isV6() && asV6().isIPv4Mapped();
   }
 
+  // @return true if address is uninitialized
+  bool empty() const { return (family_ == AF_UNSPEC); }
+
+  // @return true if address is initialized
+  explicit operator bool() const { return !empty(); }
+
   // @return true if this is an IPAddressV4 instance
   bool isV4() const { return (family_ == AF_INET); }