Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
seastar::net::inet_address: Add dns query wrapper functions for "easy…
Browse files Browse the repository at this point in the history
…" lookup
  • Loading branch information
Calle Wilund committed Feb 1, 2017
1 parent fea5d80 commit b22d1f5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def sanitize_vptr_flag(compiler):
'net/tcp.cc',
'net/dhcp.cc',
'net/tls.cc',
'net/inet_address.cc',
'net/dns.cc',
]

Expand All @@ -296,6 +295,7 @@ def sanitize_vptr_flag(compiler):
'net/posix-stack.cc',
'net/net.cc',
'net/stack.cc',
'net/inet_address.cc',
'rpc/rpc.cc',
'rpc/lz4_compressor.cc',
]
Expand Down
35 changes: 35 additions & 0 deletions net/dns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,38 @@ future<seastar::net::inet_address> seastar::net::dns::resolve_name(const sstring
future<sstring> seastar::net::dns::resolve_addr(const inet_address& addr) {
return resolver().resolve_addr(addr);
}

future<sstring> seastar::net::inet_address::hostname() const {
return dns::resolve_addr(*this);
}

future<std::vector<sstring>> seastar::net::inet_address::aliases() const {
return dns::get_host_by_addr(*this).then([](hostent e) {
return make_ready_future<std::vector<sstring>>(std::move(e.names));
});
}

future<seastar::net::inet_address> seastar::net::inet_address::find(
const sstring& name) {
return dns::resolve_name(name);
}

future<seastar::net::inet_address> seastar::net::inet_address::find(
const sstring& name, family f) {
return dns::resolve_name(name, f);
}

future<std::vector<seastar::net::inet_address>> seastar::net::inet_address::find_all(
const sstring& name) {
return dns::get_host_by_name(name).then([](hostent e) {
return make_ready_future<std::vector<seastar::net::inet_address>>(std::move(e.addr_list));
});
}

future<std::vector<seastar::net::inet_address>> seastar::net::inet_address::find_all(
const sstring& name, family f) {
return dns::get_host_by_name(name, f).then([](hostent e) {
return make_ready_future<std::vector<seastar::net::inet_address>>(std::move(e.addr_list));
});
}

2 changes: 2 additions & 0 deletions net/inet_address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "inet_address.hh"
#include "socket_defs.hh"
#include "dns.hh"

seastar::net::inet_address::inet_address()
: inet_address(::in_addr{ 0, })
Expand Down Expand Up @@ -96,6 +97,7 @@ const void * seastar::net::inet_address::data() const {
return &_in;
}


std::ostream& seastar::net::operator<<(std::ostream& os, const inet_address& addr) {
char buffer[64];
return os << inet_ntop(int(addr.in_family()), addr.data(), buffer, sizeof(buffer));
Expand Down
8 changes: 8 additions & 0 deletions net/inet_address.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public:

operator const ::in_addr&() const;
operator const ::in6_addr&() const;

future<sstring> hostname() const;
future<std::vector<sstring>> aliases() const;

static future<inet_address> find(const sstring&);
static future<inet_address> find(const sstring&, family);
static future<std::vector<inet_address>> find_all(const sstring&);
static future<std::vector<inet_address>> find_all(const sstring&, family);
};

std::ostream& operator<<(std::ostream&, const inet_address&);
Expand Down

0 comments on commit b22d1f5

Please sign in to comment.