Fix segfault
This commit is contained in:
21
include/Sockets/Commons.hpp
Normal file
21
include/Sockets/Commons.hpp
Normal 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;
|
14
include/Sockets/Endianness.hpp
Normal file
14
include/Sockets/Endianness.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <Sockets/Commons.hpp>
|
||||
|
||||
namespace Socket
|
||||
{
|
||||
namespace Endianness
|
||||
{
|
||||
u16 HostToNetworkOrder(u16 host)
|
||||
{
|
||||
return htons(host);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
@@ -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 {
|
||||
|
3
main.cpp
3
main.cpp
@@ -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);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "Sockets/IPAddress.hpp"
|
||||
#include <Sockets/Exceptions.hpp>
|
||||
#include <Sockets/Commons.hpp>
|
||||
|
||||
namespace Socket
|
||||
{
|
||||
|
Reference in New Issue
Block a user