2 * Copyright 2016 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 * Exception for invalid IP addresses.
30 class IPAddressFormatException : public std::exception {
32 explicit IPAddressFormatException(std::string msg) noexcept
33 : msg_(std::move(msg)) {}
34 IPAddressFormatException(const IPAddressFormatException&) = default;
35 IPAddressFormatException(IPAddressFormatException&&) = default;
36 IPAddressFormatException& operator=(const IPAddressFormatException&) =
38 IPAddressFormatException& operator=(IPAddressFormatException&&) = default;
40 virtual ~IPAddressFormatException() noexcept {}
41 virtual const char *what(void) const noexcept {
49 class InvalidAddressFamilyException : public IPAddressFormatException {
51 explicit InvalidAddressFamilyException(std::string msg) noexcept
52 : IPAddressFormatException(std::move(msg)) {}
53 explicit InvalidAddressFamilyException(sa_family_t family) noexcept
54 : InvalidAddressFamilyException(
55 "Address family " + detail::familyNameStr(family) +
56 " is not AF_INET or AF_INET6") {}
57 InvalidAddressFamilyException(const InvalidAddressFamilyException&) = default;
58 InvalidAddressFamilyException(InvalidAddressFamilyException&&) = default;
59 InvalidAddressFamilyException& operator=(
60 const InvalidAddressFamilyException&) = default;
61 InvalidAddressFamilyException& operator=(InvalidAddressFamilyException&&) =