Fix segfault

This commit is contained in:
2024-05-09 17:25:28 -04:00
parent 46d0315e0a
commit a693bab03e
6 changed files with 42 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
namespace Socket
{
namespace PresizedIntegerTypes
{
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using s8 = int8_t;
using s16 = int16_t;
using s32 = int32_t;
using s64 = int64_t;
}
}
using namespace Socket::PresizedIntegerTypes;

View File

@@ -0,0 +1,14 @@
#pragma once
#include <Sockets/Commons.hpp>
namespace Socket
{
namespace Endianness
{
u16 HostToNetworkOrder(u16 host)
{
return htons(host);
}
}
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <Sockets/Commons.hpp>
#include <Sockets/Sockets.hpp>
#include <cstring>
#include <array>
@@ -22,9 +23,9 @@ namespace Socket
u16 port{};
public:
static IPAddress Any(uint16_t portno) { return IPAddress{INADDR_ANY, portno};}
static IPAddress Loopback(uint16_t portno) { return IPAddress{INADDR_LOOPBACK, portno};}
static IPAddress Broadcast(uint16_t portno) { return IPAddress{INADDR_BROADCAST, portno};}
static IPAddress Any(u16 portno) { return IPAddress{INADDR_ANY, portno};}
static IPAddress Loopback(u16 portno) { return IPAddress{INADDR_LOOPBACK, portno};}
static IPAddress Broadcast(u16 portno) { return IPAddress{INADDR_BROADCAST, portno};}
// Tries to resolve an IP address from a URL
static IPAddress Resolve(std::string const& uri, u16 port);

View File

@@ -2,14 +2,6 @@
#include <cstdint>
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using s8 = int8_t;
using s16 = int16_t;
using s32 = int32_t;
using s64 = int64_t;
namespace Socket {

View File

@@ -5,6 +5,7 @@
#include <cstring>
#include <memory>
#include "Sockets/UdpSocket.hpp"
#include <Sockets/Endianness.hpp>
using namespace Socket;
@@ -59,7 +60,7 @@ void UDP_Roundtrip()
}
UdpSocket_p client;
UdpSocket_p client (new UdpSocket);
try {
client->Connect(42575);

View File

@@ -1,5 +1,6 @@
#include "Sockets/IPAddress.hpp"
#include <Sockets/Exceptions.hpp>
#include <Sockets/Commons.hpp>
namespace Socket
{