Loading...
Searching...
No Matches
Dns.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
31
33
35#include <SFML/System/Time.hpp>
36
37#include <optional>
38#include <vector>
39
40#include <cstdint>
41
42
48namespace sf::Dns
49{
60[[nodiscard]] SFML_NETWORK_API std::optional<std::vector<IpAddress>> resolve(
61 const sf::String& hostname,
62 const std::vector<sf::IpAddress>& servers = {},
63 std::optional<sf::Time> timeout = sf::seconds(1));
64
75[[nodiscard]] SFML_NETWORK_API std::vector<sf::String> queryNs(const sf::String& hostname,
76 const std::vector<sf::IpAddress>& servers = {},
77 std::optional<sf::Time> timeout = sf::seconds(1));
78
84{
86 std::uint16_t preference{};
87};
88
99[[nodiscard]] SFML_NETWORK_API std::vector<MxRecord> queryMx(const sf::String& hostname,
100 const std::vector<sf::IpAddress>& servers = {},
101 std::optional<sf::Time> timeout = sf::seconds(1));
102
108{
110 std::uint16_t port{};
111 std::uint16_t weight{};
112 std::uint16_t priority{};
113};
114
125[[nodiscard]] SFML_NETWORK_API std::vector<SrvRecord> querySrv(const sf::String& hostname,
126 const std::vector<sf::IpAddress>& servers = {},
127 std::optional<sf::Time> timeout = sf::seconds(1));
128
139[[nodiscard]] SFML_NETWORK_API std::vector<std::vector<sf::String>> queryTxt(
140 const sf::String& hostname,
141 const std::vector<sf::IpAddress>& servers = {},
142 std::optional<sf::Time> timeout = sf::seconds(1));
143
172[[nodiscard]] SFML_NETWORK_API std::optional<IpAddress> getPublicAddress(std::optional<Time> timeout = std::nullopt,
174} // namespace sf::Dns
175
176
#define SFML_NETWORK_API
Type
Type of IP address.
Definition IpAddress.hpp:58
@ IpV4
IPv4 address.
Definition IpAddress.hpp:59
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:91
constexpr Time seconds(float amount)
Construct a time value from a number of seconds.
Perform Domain Name System queries to lookup DNS records for various purposes.
Definition Dns.hpp:49
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::optional< IpAddress > getPublicAddress(std::optional< Time > timeout=std::nullopt, IpAddress::Type type=IpAddress::Type::IpV4)
Get the computer's public address via DNS.
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::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< 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< 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.
A DNS MX record.
Definition Dns.hpp:84
std::uint16_t preference
Preference of this record among others, lower values are preferred.
Definition Dns.hpp:86
sf::String exchange
Host willing to act as mail exchange.
Definition Dns.hpp:85
A DNS SRV record.
Definition Dns.hpp:108
std::uint16_t port
The port on the target host of the service.
Definition Dns.hpp:110
std::uint16_t weight
Server selection mechanism, larger weights should be given a proportionately higher probability of be...
Definition Dns.hpp:111
sf::String target
The domain name of the target host.
Definition Dns.hpp:109
std::uint16_t priority
The priority of the target host, a client must attempt to contact the target host with the lowest-num...
Definition Dns.hpp:112