Perform Domain Name System queries to lookup DNS records for various purposes. More...
Classes | |
| struct | MxRecord |
| A DNS MX record. More... | |
| struct | SrvRecord |
| A DNS SRV record. More... | |
Functions | |
| std::optional< std::vector< IpAddress > > | resolve (const sf::String &hostname, const std::vector< sf::IpAddress > &servers={}, std::optional< sf::Time > timeout=sf::seconds(1)) |
| Resolve a hostname into a list of IP addresses. | |
| std::vector< sf::String > | queryNs (const sf::String &hostname, const std::vector< sf::IpAddress > &servers={}, std::optional< sf::Time > timeout=sf::seconds(1)) |
| Query NS records for a hostname. | |
| std::vector< MxRecord > | queryMx (const sf::String &hostname, const std::vector< sf::IpAddress > &servers={}, std::optional< sf::Time > timeout=sf::seconds(1)) |
| Query MX records for a hostname. | |
| std::vector< SrvRecord > | querySrv (const sf::String &hostname, const std::vector< sf::IpAddress > &servers={}, std::optional< sf::Time > timeout=sf::seconds(1)) |
| Query SRV records for a hostname. | |
| std::vector< std::vector< sf::String > > | queryTxt (const sf::String &hostname, const std::vector< sf::IpAddress > &servers={}, std::optional< sf::Time > timeout=sf::seconds(1)) |
| Query TXT records for a hostname. | |
| std::optional< IpAddress > | getPublicAddress (std::optional< Time > timeout=std::nullopt, IpAddress::Type type=IpAddress::Type::IpV4) |
| Get the computer's public address via DNS. | |
Detailed Description
Perform Domain Name System queries to lookup DNS records for various purposes.
The sf::Dns functions allow querying the Domain Name System.
The Domain Name System contains many different kinds of records. The most common records are A and AAAA records used to resolve hostnames to IPv4 and IPv6 addresses respectively. Additionally, other kinds of records such as MX, SRV and TXT records can be queried.
Usage example:
Function Documentation
◆ getPublicAddress()
|
nodiscard |
Get the computer's public address via DNS.
The public address is the address of the computer from the point of view of the internet, i.e. something like 89.54.1.169 or 2600:1901:0:13e0::1 as opposed to a private or local address like 192.168.1.56 or fe80::1234:5678:9abc. It is necessary for communication with hosts outside of the local network.
The only way to reliably get the public address is to send data to a host on the internet and see what the origin address is; as a consequence, this function depends on both your network connection and the server, and may be very slow. You should try to use it as little as possible. Because this function depends on the network connection and on a distant server, you can specify a time limit if you don't want your program to get stuck waiting in case there is a problem; this limit is deactivated by default.
This function makes use of DNS queries get the public address.
- Parameters
-
timeout Maximum time to wait, std::nullopt to wait forever type The type of public address to get
- Returns
- Public IP address of the computer on success, std::nullopt otherwise
◆ queryMx()
|
nodiscard |
Query MX records for a hostname.
- Parameters
-
hostname Hostname to query MX records for servers The list of servers to query, if empty use the default servers timeout Query timeout if using a provided list of servers, std::nullopt to wait forever
- Returns
- List of MX records, an empty list is returned if there are no MX records for the hostname
◆ queryNs()
|
nodiscard |
Query NS records for a hostname.
- Parameters
-
hostname Hostname to query NS records for servers The list of servers to query, if empty use the default servers timeout Query timeout if using a provided list of servers, std::nullopt to wait forever
- Returns
- List of NS record strings, an empty list is returned if there are no NS records for the hostname
◆ querySrv()
|
nodiscard |
Query SRV records for a hostname.
- Parameters
-
hostname Hostname to query SRV records for servers The list of servers to query, if empty use the default servers timeout Query timeout if using a provided list of servers, std::nullopt to wait forever
- Returns
- List of SRV records, an empty list is returned if there are no SRV records for the hostname
◆ queryTxt()
|
nodiscard |
Query TXT records for a hostname.
- Parameters
-
hostname Hostname to query TXT records for servers The list of servers to query, if empty use the default servers timeout Query timeout if using a provided list of servers, std::nullopt to wait forever
- Returns
- List of TXT record string lists, an empty list is returned if there are no TXT records for the hostname
◆ resolve()
|
nodiscard |
Resolve a hostname into a list of IP addresses.
- Parameters
-
hostname Hostname to resolve servers The list of servers to query, if empty use the default servers timeout Query timeout if using a provided list of servers, std::nullopt to wait forever
- Returns
- List of IP addresses the given hostname resolves to, std::nullopt is returned if name resolution fails, an empty list is returned if the hostname could not be resolved to any address