SFML - Simple and Fast Multimedia Library

SFML 3.1.0
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
30#include <SFML/Network/Export.hpp>
31
32#include <SFML/Network/IpAddress.hpp>
33
34#include <SFML/System/String.hpp>
35#include <SFML/System/Time.hpp>
36
37#include <optional>
38#include <vector>
39
40#include <cstdint>
41
42
48 namespace 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
83 struct MxRecord
84{
85 sf::String exchange;
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
107 struct SrvRecord
108{
109 sf::String target;
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,
173 IpAddress::Type type = IpAddress::Type::IpV4);
174} // namespace sf::Dns
175
176
IpAddress.hpp
Export.hpp
SFML_NETWORK_API
#define SFML_NETWORK_API
Definition Network/Export.hpp:42
String.hpp
Time.hpp
sf::IpAddress::Type
Type
Type of IP address.
Definition IpAddress.hpp:58
sf::IpAddress::Type::IpV4
@ IpV4
IPv4 address.
Definition IpAddress.hpp:59
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:91
sf::Time::seconds
constexpr Time seconds(float amount)
Construct a time value from a number of seconds.
sf::Dns
Perform Domain Name System queries to lookup DNS records for various purposes.
Definition Dns.hpp:49
sf::Dns::resolve
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.
sf::Dns::getPublicAddress
std::optional< IpAddress > getPublicAddress(std::optional< Time > timeout=std::nullopt, IpAddress::Type type=IpAddress::Type::IpV4)
Get the computer's public address via DNS.
sf::Dns::queryTxt
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.
sf::Dns::queryNs
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.
sf::Dns::querySrv
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.
sf::Dns::queryMx
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.
sf::Dns::MxRecord
A DNS MX record.
Definition Dns.hpp:84
sf::Dns::MxRecord::preference
std::uint16_t preference
Preference of this record among others, lower values are preferred.
Definition Dns.hpp:86
sf::Dns::MxRecord::exchange
sf::String exchange
Host willing to act as mail exchange.
Definition Dns.hpp:85
sf::Dns::SrvRecord
A DNS SRV record.
Definition Dns.hpp:108
sf::Dns::SrvRecord::port
std::uint16_t port
The port on the target host of the service.
Definition Dns.hpp:110
sf::Dns::SrvRecord::weight
std::uint16_t weight
Server selection mechanism, larger weights should be given a proportionately higher probability of be...
Definition Dns.hpp:111
sf::Dns::SrvRecord::target
sf::String target
The domain name of the target host.
Definition Dns.hpp:109
sf::Dns::SrvRecord::priority
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