Skip to content
API Documentation
BastionGuard™
DnsResolver.cpp
Go to the documentation of this file.
2#include <arpa/inet.h>
3#include <netdb.h>
4#include <string.h>
5
6namespace bsc::net {
7std::string DnsResolver::reverse_lookup(const std::string& ip) const {
8 char host[NI_MAXHOST]{};
9
10 sockaddr_in sa4{};
11 sa4.sin_family = AF_INET;
12 if (inet_pton(AF_INET, ip.c_str(), &sa4.sin_addr) == 1) {
13 if (getnameinfo(reinterpret_cast<sockaddr*>(&sa4), sizeof(sa4), host, sizeof(host), nullptr, 0, NI_NAMEREQD) == 0) return host;
14 return {};
15 }
16
17 sockaddr_in6 sa6{};
18 sa6.sin6_family = AF_INET6;
19 if (inet_pton(AF_INET6, ip.c_str(), &sa6.sin6_addr) == 1) {
20 if (getnameinfo(reinterpret_cast<sockaddr*>(&sa6), sizeof(sa6), host, sizeof(host), nullptr, 0, NI_NAMEREQD) == 0) return host;
21 }
22 return {};
23}
24} // namespace bsc::net
#define AF_INET
Definition bsc_ebpf.c:56
#define AF_INET6
Definition bsc_ebpf.c:57
std::string reverse_lookup(const std::string &ip) const