#3 - DNS support + IPv6
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "io/HostResolver.hpp"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string>
|
||||
@@ -7,6 +9,7 @@
|
||||
#include <optional>
|
||||
#include <sys/socket.h>
|
||||
#include <format>
|
||||
#include <tl/expected.hpp>
|
||||
|
||||
namespace tw::net {
|
||||
|
||||
@@ -38,6 +41,24 @@ public:
|
||||
: m_storage(storage)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Look a host up, accepting a name where the constructor above takes only
|
||||
* an address literal.
|
||||
*
|
||||
* `family` should be the family of the socket the address will be used
|
||||
* with. The default suits an address that is only being validated or
|
||||
* displayed, and takes whatever the name resolves to.
|
||||
*/
|
||||
static tl::expected<Address, ResolutionError>
|
||||
resolve(const std::string& host, int port, sa_family_t family = AF_UNSPEC) {
|
||||
auto storage_r = resolve_host(host, port, family);
|
||||
if(!storage_r) {
|
||||
return tl::make_unexpected(storage_r.error());
|
||||
}
|
||||
|
||||
return Address(std::move(storage_r.value()));
|
||||
}
|
||||
|
||||
/** Return a const pointer suitable for connect / sendto / bind. */
|
||||
const struct sockaddr* sockaddr() const {
|
||||
return reinterpret_cast<const struct sockaddr*>(&m_storage);
|
||||
|
||||
Reference in New Issue
Block a user