From 8d0aa27ccf14d76456b6b61dd705f7993229654a Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 13 Dec 2021 19:02:15 +0800 Subject: *misc --- Client/Source/Network/Address.h | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'Client/Source/Network/Address.h') diff --git a/Client/Source/Network/Address.h b/Client/Source/Network/Address.h index e69de29..fcace88 100644 --- a/Client/Source/Network/Address.h +++ b/Client/Source/Network/Address.h @@ -0,0 +1,59 @@ +#pragma once + +#include "../Utilities/Type.h" + +#include +#include +#ifdef _WIN32 +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif +#include +#include +#include +#else +#include +#include +#endif + +class IPv6AddressBytes +{ +public: + u8 bytes[16]; + IPv6AddressBytes() { memset(bytes, 0, 16); } +}; + +class Address +{ +public: + Address(); + Address(u32 address, u16 port); + Address(u8 a, u8 b, u8 c, u8 d, u16 port); + Address(const IPv6AddressBytes *ipv6_bytes, u16 port); + bool operator==(const Address &address); + bool operator!=(const Address &address); + // Resolve() may throw ResolveError (address is unchanged in this case) + void Resolve(const char *name); + struct sockaddr_in getAddress() const; + unsigned short getPort() const; + void setAddress(u32 address); + void setAddress(u8 a, u8 b, u8 c, u8 d); + void setAddress(const IPv6AddressBytes *ipv6_bytes); + struct sockaddr_in6 getAddress6() const; + int getFamily() const; + bool isIPv6() const; + bool isZero() const; + void setPort(unsigned short port); + void print(std::ostream *s) const; + std::string serializeString() const; + bool isLocalhost() const; + +private: + unsigned int m_addr_family = 0; + union + { + struct sockaddr_in ipv4; + struct sockaddr_in6 ipv6; + } m_address; + u16 m_port = 0; // Port is separate from sockaddr structures +}; -- cgit v1.1-26-g67d0