extend future api with Future<T>::poll
[folly.git] / folly / IPAddress.h
index c5f57aadd9584f754d89288bbca46c7a351e5574..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.
 
 #include <boost/operators.hpp>
 
-#include "folly/Format.h"
-#include "folly/Range.h"
-#include "folly/IPAddressException.h"
-#include "folly/IPAddressV4.h"
-#include "folly/IPAddressV6.h"
-#include "folly/detail/IPAddress.h"
+#include <folly/Conv.h>
+#include <folly/Format.h>
+#include <folly/Range.h>
+#include <folly/IPAddressException.h>
+#include <folly/IPAddressV4.h>
+#include <folly/IPAddressV6.h>
+#include <folly/detail/IPAddress.h>
 
 namespace folly {
 
@@ -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); }
 
@@ -310,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()