8 #ifndef _INC_cNetHost_H
9 #define _INC_cNetHost_H
10 #ifndef NO_PRAGMA_ONCE
26 #if defined(_WINDLL) || defined(USE_64BIT) || defined(__linux__) || (defined(_MSC_VER) && ( _MSC_VER >= 1600 ))
27 #define USE_WINSOCK2_ADDR
37 static const size_t k_SIZE_M48 = 6;
38 static const size_t k_SIZE_E48 = 6;
39 static const size_t k_SIZE_E64 = 8;
40 static const size_t k_SIZE_MAX = 8;
42 BYTE m_bAddr[k_SIZE_MAX];
51 ::memcpy(m_bAddr, mac.m_bAddr,
sizeof(m_bAddr));
59 bool put_MacStr(
const char* pszMac);
60 HRESULT SetMacAddrFromAdapter(
sa_family_t nAddressFamily = AF_INET,
int nAdapterIndex = 0);
77 #ifdef USE_LITTLE_ENDIAN
78 static const UINT32 k_LOOPBACK_N = 0x0100007f;
80 static const UINT32 k_LOOPBACK_N = 0x7F000001;
82 static const UINT32 k_BROADCAST = 0xFFFFFFFF;
90 m_ipa4.s_addr = INADDR_ANY;
113 return m_ipa4.s_addr != INADDR_ANY;
118 return m_ipa4.s_addr == k_LOOPBACK_N;
123 return m_ipa4.s_addr == k_BROADCAST;
128 UINT32 ip4h = get_HostIp4_H();
130 switch ((ip4h & IN_CLASSA_NET) >> IN_CLASSA_NSHIFT)
139 if (ip4h == INADDR_LOOPBACK)
143 bClassB = (BYTE)((ip4h >> IN_CLASSB_NSHIFT) & 0xFF);
144 if (bClassB >= 16 && bClassB <= 31)
148 bClassB = (BYTE)((ip4h >> IN_CLASSB_NSHIFT) & 0xFF);
153 if (ip4h == INADDR_BROADCAST)
165 return (m_ipa4.s_addr & dwMaskN) == (ip.
m_ipa4.s_addr & dwMaskN);
169 return m_ipa4.s_addr == ip.m_ipa4.s_addr;
174 m_ipa4.s_addr = INADDR_NONE;
179 operator in_addr() const noexcept
188 return ((
const BYTE*)&m_ipa4.s_addr)[i];
215 m_ipa4.s_addr = k_LOOPBACK_N;
227 HRESULT put_HostStr(
const char* pszIP);
228 static StrLen_t GRAYCALL GetIP4Format(
const char* pszIP,
bool bTerm =
true);
264 pU[2].
u_dw = 0xFFFF0000;
265 pU[3].
u_dw = ip.s_addr;
279 bool isHostValid()
const;
280 bool isHostLoopback()
const;
281 bool isHostPrivate()
const;
282 bool isHostIP4()
const;
284 static StrLen_t GRAYCALL GetIP6Format(
const char* pszIP,
bool bTerm =
true);
286 HRESULT put_HostStr(
const char* pszIP);
289 operator in6_addr() const noexcept
299 bool operator == (const in6_addr& ip) const noexcept
301 return !::memcmp(&m_ipa6, &ip,
sizeof(m_ipa6));
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
short sa_family_t
enum of network family types. e.g. AF_UNSPEC=0, AF_INET = 2, AF_INET6 = 23, AF_NETBIOS = 17,...
Definition: cNetHost.h:19
Definition: cNetHost.h:64
static const in_addr k_AddrBroadcast
Broadcast. INADDR_BROADCAST.
Definition: cNetHost.h:231
cNetHost4(const char *pszIP)
Definition: cNetHost.h:101
UINT32 get_HostIp4_H() const noexcept
Definition: cNetHost.h:195
bool isHostValid() const noexcept
Definition: cNetHost.h:110
void SetEmptyHostAddr() noexcept
Definition: cNetHost.h:171
cNetHost4(const in_addr &ip) noexcept
Definition: cNetHost.h:97
HASHCODE32_t get_HashCode() const noexcept
Definition: cNetHost.h:217
void put_HostIp4(in_addr addr4) noexcept
Definition: cNetHost.h:201
in_addr get_HostIp4() const noexcept
Definition: cNetHost.h:190
void put_HostLoopback() noexcept
Definition: cNetHost.h:212
cNetHost4() noexcept
Definition: cNetHost.h:88
BYTE GetByte(int i=0) const
Definition: cNetHost.h:184
bool isHostLocalTo(const cNetHost4 &ip, UINT32 dwMask=0xFFFFFF00) const noexcept
Definition: cNetHost.h:159
in_addr m_ipa4
(network order bytes) (4 bytes)
Definition: cNetHost.h:85
bool isHostPrivate() const
Definition: cNetHost.h:125
static const in_addr k_AddrNull
invalid address. INADDR_ANY (NOT INADDR_NONE)
Definition: cNetHost.h:230
void put_HostIp4_H(UINT32 uIP4) noexcept
Definition: cNetHost.h:206
bool isHostLoopback() const noexcept
Definition: cNetHost.h:115
cNetHost4(UINT uIP4) noexcept
Definition: cNetHost.h:92
UNITTEST_FRIEND(cNetHost)
bool isHostBroadcast() const noexcept
Definition: cNetHost.h:120
Definition: cNetHost.h:237
void SetEmptyHostAddr() noexcept
Definition: cNetHost.h:274
const in6_addr & get_HostIp6() const noexcept
Definition: cNetHost.h:293
in6_addr m_ipa6
(network order bytes) (16 bytes)
Definition: cNetHost.h:247
cNetHost6() noexcept
Definition: cNetHost.h:250
cNetHost6(const in_addr &ip)
Definition: cNetHost.h:258
static const in6_addr k_AddrNull
invalid address for initialize.
Definition: cNetHost.h:245
cNetHost6(const char *pszIP)
Definition: cNetHost.h:268
cNetHost6(const in6_addr &ip) noexcept
Definition: cNetHost.h:254
Definition: cNetHost.h:31
cNetMacAddr() noexcept
Definition: cNetHost.h:45
cNetMacAddr(const cNetMacAddr &mac) noexcept
Definition: cNetHost.h:49
cNetMacAddr(const char *pszMac)
Definition: cNetHost.h:53
UNITTEST2_PREDEF(cQuadtree)
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
UINT_PTR HASHCODE_t
could hold a pointer converted to a number? maybe 64 or 32 bit ? same as size_t.
Definition: GrayCore.h:116
UINT32 HASHCODE32_t
always 32 bits.
Definition: GrayCore.h:117
bool operator==(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:250
static TYPE NtoH(TYPE nVal) noexcept
Definition: cMem.h:502
static TYPE HtoN(TYPE nVal) noexcept
Definition: cMem.h:491
static void Zero(void *pData, size_t nSizeBlock) noexcept
Definition: cMem.h:100
UINT32 u_dw
32 bit unsigned
Definition: cTypes.h:78