X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FIPAddressV6.h;h=161a2404b620868adf4c1406d526846f8f6453c6;hb=30c1e1dcee8143c6804231a009ae939e5793dc56;hp=05cc5bdc4b2dff7bd10e24bb2789553fecbd7537;hpb=9432d632ddea663265b135d859c18f2adda982f7;p=folly.git diff --git a/folly/IPAddressV6.h b/folly/IPAddressV6.h index 05cc5bdc..161a2404 100644 --- a/folly/IPAddressV6.h +++ b/folly/IPAddressV6.h @@ -24,10 +24,13 @@ #include #include -#include +#include +#include +#include #include #include #include +#include namespace folly { @@ -91,17 +94,27 @@ class IPAddressV6 { 8 /*words*/ * 4 /*hex chars per word*/ + 7 /*separators*/; // returns true iff the input string can be parsed as an ipv6-address - static bool validate(StringPiece ip); + static bool validate(StringPiece ip) noexcept; /** * Create a new IPAddress instance from the provided binary data. * @throws IPAddressFormatException if the input length is not 16 bytes. */ - static IPAddressV6 fromBinary(ByteRange bytes) { - IPAddressV6 addr; - addr.setFromBinary(bytes); - return addr; - } + static IPAddressV6 fromBinary(ByteRange bytes); + + /** + * Non-throwing version of fromBinary(). + * On failure returns IPAddressFormatError. + */ + static Expected tryFromBinary( + ByteRange bytes) noexcept; + + /** + * Tries to create a new IPAddressV6 instance from provided string and + * returns it on success. Returns IPAddressFormatError on failure. + */ + static Expected tryFromString( + StringPiece str) noexcept; /** * Create a new IPAddress instance from the ip6.arpa representation. @@ -130,13 +143,13 @@ class IPAddressV6 { explicit IPAddressV6(StringPiece ip); // ByteArray16 constructor - explicit IPAddressV6(const ByteArray16& src); + explicit IPAddressV6(const ByteArray16& src) noexcept; // in6_addr constructor - explicit IPAddressV6(const in6_addr& src); + explicit IPAddressV6(const in6_addr& src) noexcept; // sockaddr_in6 constructor - explicit IPAddressV6(const sockaddr_in6& src); + explicit IPAddressV6(const sockaddr_in6& src) noexcept; /** * Create a link-local IPAddressV6 from the specified ethernet MAC address. @@ -231,6 +244,16 @@ class IPAddressV6 { */ Optional getMacAddressFromLinkLocal() const; + /** + * Return the mac address if this is an auto-configured IPv6 address based on + * EUI-64 + * + * @return an Optional union representing the mac address. + * If the address is not based on EUI-64 it will return an empty Optional. + * You can use Optional::value() to check whether the mac address is not null. + */ + Optional getMacAddressFromEUI64() const; + /** * Return true if this is a multicast address. */ @@ -395,9 +418,10 @@ class IPAddressV6 { /** * Set the current IPAddressV6 object to have the address specified by bytes. - * @throws IPAddressFormatException if bytes.size() is not 16. + * Returns IPAddressFormatError if bytes.size() is not 16. */ - void setFromBinary(ByteRange bytes); + Expected trySetFromBinary( + ByteRange bytes) noexcept; }; // boost::hash uses hash_value() so this allows boost::hash to work