forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.hh
45 lines (37 loc) · 1.04 KB
/
dns.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Copyright 2015 Cloudius Systems
*/
#pragma once
#include <boost/asio/ip/address_v4.hpp>
#include <sys/socket.h>
#include "core/sstring.hh"
#include "core/future.hh"
namespace dns {
enum class address_family {
INET = AF_INET,
INET6 = AF_INET6
};
union host_addr {
in_addr in;
in6_addr in6;
};
struct hostent {
sstring name;
std::vector<sstring> aliases;
address_family addrtype;
std::vector<host_addr> addresses;
};
// ATTENTION: this is stub only. It translates "localhost" into loopback address
// otherwise it assumes that string is an IP address already
future<hostent> gethostbyname(sstring name) {
hostent e = {name, {}, address_family::INET};
host_addr a;
if (name == "localhost") {
a.in.s_addr = static_cast<in_addr_t>(boost::asio::ip::address_v4::loopback().to_ulong());
} else {
a.in.s_addr = static_cast<in_addr_t>(boost::asio::ip::address_v4::from_string(name).to_ulong());
}
e.addresses.push_back(std::move(a));
return make_ready_future<hostent>(std::move(e));
}
}