/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * A representation of an IPv4 address * * @class folly::IPAddressV4 * @see IPAddress * @see IPAddressV6 */ #pragma once #include <cstring> #include <array> #include <functional> #include <iosfwd> #include <folly/Expected.h> #include <folly/FBString.h> #include <folly/IPAddressException.h> #include <folly/Range.h> #include <folly/detail/IPAddress.h> #include <folly/hash/Hash.h> namespace folly { class IPAddress; class IPAddressV4; class IPAddressV6; /** * Pair of IPAddressV4, netmask */ CIDRNetworkV4; /** * Specialization of `std::array` for IPv4 addresses */ ByteArray4; class IPAddressV4 { … }; /** * `boost::hash` uses hash_value() so this allows `boost::hash` to work * automatically for IPAddressV4 */ size_t hash_value(const IPAddressV4& addr); /** * Appends a string representation of the IP address to the stream using str(). */ std::ostream& operator<<(std::ostream& os, const IPAddressV4& addr); /** * @overloadbrief Define toAppend() to allow IPAddress to be used with * `folly::to<string>` */ void toAppend(IPAddressV4 addr, std::string* result); void toAppend(IPAddressV4 addr, fbstring* result); /** * Return true if two addresses are equal. */ inline bool operator==(const IPAddressV4& addr1, const IPAddressV4& addr2) { … } /** * Return true if addr1 < addr2. */ inline bool operator<(const IPAddressV4& addr1, const IPAddressV4& addr2) { … } /** * Return true if addr1 != addr2. */ inline bool operator!=(const IPAddressV4& addr1, const IPAddressV4& addr2) { … } /** * Return true if addr1 > addr2. */ inline bool operator>(const IPAddressV4& addr1, const IPAddressV4& addr2) { … } /** * Return true if addr1 <= addr2. */ inline bool operator<=(const IPAddressV4& addr1, const IPAddressV4& addr2) { … } /** * Return true if addr1 >= addr2. */ inline bool operator>=(const IPAddressV4& addr1, const IPAddressV4& addr2) { … } } // namespace folly namespace std { template <> struct hash<folly::IPAddressV4> { … }; } // namespace std