|
join 1.0
lightweight network framework library
|
basic domain name resolution class. More...
#include <resolver.hpp>
Public Types | |
| enum | RecordType : uint16_t { A = 1 , NS = 2 , CNAME = 5 , SOA = 6 , PTR = 12 , MX = 15 , AAAA = 28 } |
| DNS record types. More... | |
| enum | RecordClass : uint16_t { IN = 1 } |
| DNS record classes. More... | |
| using | DnsNotify = std::function <void (const DnsPacket&)> |
| notification callback definition. | |
Public Member Functions | |
| Resolver () | |
| default constructor. | |
| Resolver (const std::string &interface) | |
| create the Resolver instance binded to the given interface. | |
| Resolver (const Resolver &other)=delete | |
| copy constructor. | |
| Resolver & | operator= (const Resolver &other)=delete |
| copy assignment operator. | |
| Resolver (Resolver &&other)=delete | |
| move constructor. | |
| Resolver & | operator= (Resolver &&other)=delete |
| move assignment operator. | |
| virtual | ~Resolver ()=default |
| destroy instance. | |
| IpAddressList | resolveAllHost (const std::string &host, int family, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host name and return all IP address found. | |
| IpAddressList | resolveAllHost (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host name and return all IP address found. | |
| IpAddress | resolveHost (const std::string &host, int family, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host name using address family. | |
| IpAddress | resolveHost (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host name. | |
| AliasList | resolveAllAddress (const IpAddress &address, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve all host address. | |
| std::string | resolveAddress (const IpAddress &address, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host address. | |
| ServerList | resolveAllNameServer (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve all host name server. | |
| std::string | resolveNameServer (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host name server. | |
| std::string | resolveAuthority (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host start of authority name server. | |
| ExchangerList | resolveAllMailExchanger (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve all host mail exchanger. | |
| std::string | resolveMailExchanger (const std::string &host, const IpAddress &server, uint16_t port=dnsPort, int timeout=5000) |
| resolve host mail exchanger. | |
Static Public Member Functions | |
| static IpAddressList | nameServers () |
| get IP address of the currently configured name servers. | |
| static IpAddressList | resolveAllHost (const std::string &host, int family) |
| resolve host name and return all IP address found. | |
| static IpAddressList | resolveAllHost (const std::string &host) |
| resolve host name and return all IP address found. | |
| static IpAddress | resolveHost (const std::string &host, int family) |
| resolve host name using address family. | |
| static IpAddress | resolveHost (const std::string &host) |
| resolve host name. | |
| static AliasList | resolveAllAddress (const IpAddress &address) |
| resolve all host address. | |
| static std::string | resolveAddress (const IpAddress &address) |
| resolve host address. | |
| static ServerList | resolveAllNameServer (const std::string &host) |
| resolve all host name server. | |
| static std::string | resolveNameServer (const std::string &host) |
| resolve host name server. | |
| static std::string | resolveAuthority (const std::string &host) |
| resolve host start of authority name server. | |
| static ExchangerList | resolveAllMailExchanger (const std::string &host) |
| resolve all host mail exchanger. | |
| static std::string | resolveMailExchanger (const std::string &host) |
| resolve host mail exchanger. | |
| static uint16_t | resolveService (const std::string &service) |
| resolve service name. | |
| static std::string | typeName (uint16_t recordType) |
| get record type name. | |
| static std::string | className (uint16_t recordClass) |
| get record class name. | |
Public Attributes | |
| DnsNotify | _onSuccess |
| callback called when a lookup sequence succeed. | |
| DnsNotify | _onFailure |
| callback called when a lookup sequence failed. | |
Static Public Attributes | |
| static constexpr uint16_t | dnsPort = 53 |
| default DNS port. | |
Protected Member Functions | |
| int | lookup (DnsPacket &packet, int timeout) |
| send the DNS request. | |
| void | setHeader (uint16_t id, uint16_t flags, uint16_t qcount, uint16_t ancount, uint16_t nscount, uint16_t arcount, std::stringstream &data) |
| set DNS header. | |
| void | getHeader (uint16_t &id, uint16_t &flags, uint16_t &qcount, uint16_t &ancount, uint16_t &nscount, uint16_t &arcount, std::stringstream &data) |
| get DNS header. | |
| void | notify (const DnsNotify &function, const DnsPacket &packet) |
| safe way to notify DNS events. | |
Static Protected Member Functions | |
| static void | encodeName (const std::string &host, std::stringstream &data) |
| encode name. | |
| static std::string | decodeName (std::stringstream &data) |
| decode name. | |
| static std::string | decodeMail (std::stringstream &data) |
| decode mail. | |
| static void | encodeQuestion (const std::string &host, uint16_t type, uint16_t dnsclass, std::stringstream &data) |
| decode question record. | |
| static QuestionRecord | decodeQuestion (std::stringstream &data) |
| decode question record. | |
| static AnswerRecord | decodeAnswer (std::stringstream &data) |
| decode answer record. | |
| static std::error_code | parseError (int error) |
| convert DNS error to system error code. | |
Protected Attributes | |
| std::string | _interface |
| interface name. | |
basic domain name resolution class.
| using join::Resolver::DnsNotify = std::function <void (const DnsPacket&)> |
notification callback definition.
| enum join::Resolver::RecordClass : uint16_t |
| enum join::Resolver::RecordType : uint16_t |
| Resolver::Resolver | ( | ) |
default constructor.
| Resolver::Resolver | ( | const std::string & | interface | ) |
create the Resolver instance binded to the given interface.
| interface | interface to use. |
|
delete |
copy constructor.
| other | other object to copy. |
|
delete |
move constructor.
| other | other object to move. |
|
virtualdefault |
destroy instance.
|
static |
get record class name.
| recordType | record class. |
|
staticprotected |
decode answer record.
| data | stream where the encoded mail is stored. |
|
staticprotected |
decode mail.
| data | stream where the encoded mail is stored. |
|
staticprotected |
decode name.
| data | stream where the encoded name is stored. |
|
staticprotected |
decode question record.
| data | stream where the encoded mail is stored. |
|
staticprotected |
encode name.
| host | host name to encode. |
| data | data stream where to store encoded name. |
|
staticprotected |
decode question record.
| host | host name. |
| type | record type. |
| dnsclass | record class. |
| data | data stream where to store encoded question. |
|
protected |
get DNS header.
| id | request id. |
| flags | flags. |
| qcount | question record count. |
| ancount | answer record count. |
| nscount | name server record count. |
| arcount | additional record count. |
| data | data stream where to read header. |
|
protected |
send the DNS request.
| packet | DNS packet to send. |
| timeout | timeout in milliseconds. |
|
static |
get IP address of the currently configured name servers.
safe way to notify DNS events.
| function | function to call. |
| packet | DNS packet. |
copy assignment operator.
| other | other object to copy. |
move assignment operator.
| other | other object to move. |
|
staticprotected |
convert DNS error to system error code.
| error | DNS error number. |
|
static |
resolve host address.
| host | host address to resolve. |
| std::string Resolver::resolveAddress | ( | const IpAddress & | address, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host address.
| address | host address to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
resolve all host address.
| address | host address to resolve. |
| AliasList Resolver::resolveAllAddress | ( | const IpAddress & | address, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve all host address.
| address | host address to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host name and return all IP address found.
| host | host name to resolve. |
| IpAddressList Resolver::resolveAllHost | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host name and return all IP address found.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host name and return all IP address found.
| host | host name to resolve. |
| family | address family. |
| IpAddressList Resolver::resolveAllHost | ( | const std::string & | host, |
| int | family, | ||
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host name and return all IP address found.
| host | host name to resolve. |
| family | address family. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve all host mail exchanger.
| host | host name to resolve. |
| ExchangerList Resolver::resolveAllMailExchanger | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve all host mail exchanger.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve all host name server.
| host | host name to resolve. |
| ServerList Resolver::resolveAllNameServer | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve all host name server.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host start of authority name server.
| host | host name to resolve. |
| std::string Resolver::resolveAuthority | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host start of authority name server.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host name.
| host | host name to resolve. |
| IpAddress Resolver::resolveHost | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host name.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host name using address family.
| host | host name to resolve. |
| family | address family. |
| IpAddress Resolver::resolveHost | ( | const std::string & | host, |
| int | family, | ||
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host name using address family.
| host | host name to resolve. |
| family | address family. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host mail exchanger.
| host | host name to resolve. |
| std::string Resolver::resolveMailExchanger | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host mail exchanger.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve host name server.
| host | host name to resolve. |
| std::string Resolver::resolveNameServer | ( | const std::string & | host, |
| const IpAddress & | server, | ||
| uint16_t | port = dnsPort, | ||
| int | timeout = 5000 ) |
resolve host name server.
| host | host name to resolve. |
| server | server address. |
| port | server port. |
| timeout | timeout in milliseconds (default: 5000). |
|
static |
resolve service name.
| service | service name to resolve (ex. "http", "ftp", "ssh" etc...). |
|
protected |
set DNS header.
| id | request id. |
| flags | flags. |
| qcount | question record count. |
| ancount | answer record count. |
| nscount | name server record count. |
| arcount | additional record count. |
| data | data stream where to write header. |
|
static |
get record type name.
| recordType | record type. |
|
protected |
interface name.
| DnsNotify join::Resolver::_onFailure |
callback called when a lookup sequence failed.
| DnsNotify join::Resolver::_onSuccess |
callback called when a lookup sequence succeed.
|
staticconstexpr |
default DNS port.