2 * Copyright 2014-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <folly/CPortability.h>
23 #include <folly/detail/IPAddress.h>
28 * Error codes for non-throwing interface of IPAddress family of functions.
30 enum class IPAddressFormatError { INVALID_IP, UNSUPPORTED_ADDR_FAMILY };
33 * Wraps error from parsing IP/MASK string
35 enum class CIDRNetworkError {
37 INVALID_IP_SLASH_CIDR,
44 * Exception for invalid IP addresses.
46 class FOLLY_EXPORT IPAddressFormatException : public std::exception {
48 explicit IPAddressFormatException(std::string msg) noexcept
49 : msg_(std::move(msg)) {}
50 IPAddressFormatException(const IPAddressFormatException&) = default;
51 IPAddressFormatException(IPAddressFormatException&&) = default;
52 IPAddressFormatException& operator=(const IPAddressFormatException&) =
54 IPAddressFormatException& operator=(IPAddressFormatException&&) = default;
56 ~IPAddressFormatException() noexcept override {}
57 const char* what() const noexcept override {
65 class FOLLY_EXPORT InvalidAddressFamilyException
66 : public IPAddressFormatException {
68 explicit InvalidAddressFamilyException(std::string msg) noexcept
69 : IPAddressFormatException(std::move(msg)) {}
70 explicit InvalidAddressFamilyException(sa_family_t family) noexcept
71 : InvalidAddressFamilyException(
72 "Address family " + detail::familyNameStr(family) +
73 " is not AF_INET or AF_INET6") {}
74 InvalidAddressFamilyException(const InvalidAddressFamilyException&) = default;
75 InvalidAddressFamilyException(InvalidAddressFamilyException&&) = default;
76 InvalidAddressFamilyException& operator=(
77 const InvalidAddressFamilyException&) = default;
78 InvalidAddressFamilyException& operator=(InvalidAddressFamilyException&&) =