2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2016 ScyllaDB.
25 #include <sys/types.h>
26 #include <netinet/in.h>
30 #include <seastar/core/future.hh>
31 #include <seastar/core/sstring.hh>
39 class unknown_host : public std::invalid_argument {
41 using invalid_argument::invalid_argument;
46 enum class family : sa_family_t {
47 INET = AF_INET, INET6 = AF_INET6
57 uint32_t _scope = invalid_scope;
59 static constexpr uint32_t invalid_scope = std::numeric_limits<uint32_t>::max();
63 inet_address(::in_addr i);
64 inet_address(::in6_addr i, uint32_t scope = invalid_scope);
65 // NOTE: does _not_ resolve the address. Only parses
66 // ipv4/ipv6 numerical address
67 inet_address(const sstring&);
68 inet_address(inet_address&&) = default;
69 inet_address(const inet_address&) = default;
71 inet_address(const ipv4_address&);
72 inet_address(const ipv6_address&, uint32_t scope = invalid_scope);
75 ipv4_address as_ipv4_address() const;
76 ipv6_address as_ipv6_address() const;
78 inet_address& operator=(const inet_address&) = default;
79 bool operator==(const inet_address&) const;
81 family in_family() const {
85 bool is_ipv6() const {
86 return _in_family == family::INET6;
88 bool is_ipv4() const {
89 return _in_family == family::INET;
93 const void * data() const;
95 uint32_t scope() const {
99 operator ::in_addr() const;
100 operator ::in6_addr() const;
102 operator ipv6_address() const;
104 future<sstring> hostname() const;
105 future<std::vector<sstring>> aliases() const;
107 static future<inet_address> find(const sstring&);
108 static future<inet_address> find(const sstring&, family);
109 static future<std::vector<inet_address>> find_all(const sstring&);
110 static future<std::vector<inet_address>> find_all(const sstring&, family);
112 static compat::optional<inet_address> parse_numerical(const sstring&);
115 std::ostream& operator<<(std::ostream&, const inet_address&);
116 std::ostream& operator<<(std::ostream&, const inet_address::family&);
123 struct hash<seastar::net::inet_address> {
124 size_t operator()(const seastar::net::inet_address&) const;