2 * Copyright 2017 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.
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 * Exception for invalid IP addresses.
35 class IPAddressFormatException : public std::exception {
37 explicit IPAddressFormatException(std::string msg) noexcept
38 : msg_(std::move(msg)) {}
39 IPAddressFormatException(const IPAddressFormatException&) = default;
40 IPAddressFormatException(IPAddressFormatException&&) = default;
41 IPAddressFormatException& operator=(const IPAddressFormatException&) =
43 IPAddressFormatException& operator=(IPAddressFormatException&&) = default;
45 ~IPAddressFormatException() noexcept override {}
46 const char* what() const noexcept override {
54 class InvalidAddressFamilyException : public IPAddressFormatException {
56 explicit InvalidAddressFamilyException(std::string msg) noexcept
57 : IPAddressFormatException(std::move(msg)) {}
58 explicit InvalidAddressFamilyException(sa_family_t family) noexcept
59 : InvalidAddressFamilyException(
60 "Address family " + detail::familyNameStr(family) +
61 " is not AF_INET or AF_INET6") {}
62 InvalidAddressFamilyException(const InvalidAddressFamilyException&) = default;
63 InvalidAddressFamilyException(InvalidAddressFamilyException&&) = default;
64 InvalidAddressFamilyException& operator=(
65 const InvalidAddressFamilyException&) = default;
66 InvalidAddressFamilyException& operator=(InvalidAddressFamilyException&&) =