diff options
Diffstat (limited to 'NetEx/NetAddr.h')
-rw-r--r-- | NetEx/NetAddr.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/NetEx/NetAddr.h b/NetEx/NetAddr.h index 82f3420..b3d1c87 100644 --- a/NetEx/NetAddr.h +++ b/NetEx/NetAddr.h @@ -3,41 +3,44 @@ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. - AUTHOR: John DiCamillo + AUTHOR: John DiCamillo - OVERVIEW - ======== - Network Address (specifically, Internet Protocol) + OVERVIEW + ======== + Network Address (specifically, Internet Protocol) */ - #ifndef NetAddr_h #define NetAddr_h -#include <windows.h> -#include <winsock.h> +#ifdef _WIN32 +#include <winsock2.h> +#else +#include <sys/socket.h> +#endif + +#include <cstdint> -// +-------------------------------------------------------------------+ class NetAddr { public: static const char* TYPENAME() { return "NetAddr"; } - NetAddr(const char* a, WORD p=0); - NetAddr(DWORD a=0, WORD p=0); + NetAddr(const char* a, std::uint16_t p=0); + NetAddr(std::uint32_t a=0, std::uint16_t p=0); NetAddr(const NetAddr& n); int operator == (const NetAddr& a) const { return addr==a.addr && port==a.port; } - DWORD IPAddr() const { return addr; } - BYTE B4() const { return (BYTE) ((addr & 0xff000000) >> 24); } - BYTE B3() const { return (BYTE) ((addr & 0x00ff0000) >> 16); } - BYTE B2() const { return (BYTE) ((addr & 0x0000ff00) >> 8); } - BYTE B1() const { return (BYTE) ((addr & 0x000000ff) ); } + std::uint32_t IPAddr() const { return addr; } + std::uint8_t B4() const { return static_cast<std::uint8_t>((addr & 0xff000000) >> 24); } + std::uint8_t B3() const { return static_cast<std::uint8_t>((addr & 0x00ff0000) >> 16); } + std::uint8_t B2() const { return static_cast<std::uint8_t>((addr & 0x0000ff00) >> 8); } + std::uint8_t B1() const { return static_cast<std::uint8_t>((addr & 0x000000ff) ); } - WORD Port() const { return port; } + std::uint16_t Port() const { return port; } void SetPort(WORD p) { port = p; } sockaddr* GetSockAddr() const; @@ -49,8 +52,8 @@ public: private: void Init(); - DWORD addr; // IP addr in host byte order - WORD port; // IP port in host byte order + std::uint32_t addr; // IP addr in host byte order + std::uint16_t port; // IP port in host byte order sockaddr_in sadr; }; |