working commit

This commit is contained in:
2026-04-23 14:53:39 +02:00
parent fa1c3ce9e2
commit cf45872d91
12 changed files with 1786 additions and 26 deletions
+11 -10
View File
@@ -17,24 +17,25 @@ extern "C" {
#include <resolver.hpp>
#include <udpclient.hpp>
UDPClient::UDPClient(void) {
sockfd = 0;
rmax = 2024;
};
std::expected<void, std::string> UDPClient::Bind(std::string hostname, int nport) {
std::expected<void, std::string> UDPClient::Bind(std::string naddress, int nport) {
port = nport;
address = naddress;
Resolver resolver;
auto resolveRes = resolver.Resolve(hostname);
if (!resolveRes) {
auto msg = std::format("Cannot resolve hostname {}: {}", hostname, resolveRes.error());
return std::unexpected(msg);
struct sockaddr_in sa;
if (inet_pton(AF_INET, address.c_str(), &(sa.sin_addr)) == 1) {
family = AF_INET;
} else if (inet_pton(AF_INET6, address.c_str(), &(sa.sin_addr)) == 1) {
family = AF_INET6;
} else {
int errnocopy = errno;
std::string error = std::strerror(errnocopy);
return std::unexpected("Incorrect address " + naddress);
}
auto addr = resolveRes.value();
address = addr.GetAddress();
family = addr.GetFamily();
if ((sockfd = socket(family, SOCK_DGRAM, 0)) < 0) {
int errnocopy = errno;