added qse_ip4adtoprefix()

added Socket::isOpen()
This commit is contained in:
hyung-hwan 2020-08-20 16:21:36 +00:00
parent 42e21d9e1e
commit a83005ca99
5 changed files with 67 additions and 6 deletions

View File

@ -381,6 +381,15 @@ QSE_EXPORT int qse_prefixtoip6ad (
qse_ip6ad_t* ipad qse_ip6ad_t* ipad
); );
/*
* The qse_ip4adtoprefix() function returns the prefix length
* of the given IPv4 address mask.
*/
QSE_EXPORT int qse_ip4adtoprefix (
const qse_ip4ad_t* ipad
);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -55,6 +55,7 @@ public:
void close () QSE_CPP_NOEXCEPT; void close () QSE_CPP_NOEXCEPT;
qse_sck_hnd_t getHandle() const QSE_CPP_NOEXCEPT { return this->handle; } qse_sck_hnd_t getHandle() const QSE_CPP_NOEXCEPT { return this->handle; }
bool isOpen() const QSE_CPP_NOEXCEPT { return this->handle != QSE_INVALID_SCKHND; }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -734,3 +734,54 @@ int qse_prefixtoip6ad (int prefix, qse_ip6ad_t* ipad)
return 0; return 0;
} }
#define __COUNTUP(x,cnt,rest) \
switch (x) \
{ \
case 0xFF000000: \
cnt += 8; break; \
case 0x00000000: \
if (rest) return -1; break; \
case 0xFE000000: cnt++; \
case 0xFC000000: cnt++; \
case 0xF8000000: cnt++; \
case 0XF0000000: cnt++; \
case 0xE0000000: cnt++; \
case 0xC0000000: cnt++; \
case 0x80000000: cnt++; \
if (rest) return -1; break; \
default: return -1; \
}
int qse_ip4adtoprefix (const qse_ip4ad_t* ipad)
{
int pfx = 0;
qse_uint32_t x, nm;
nm = qse_ntoh32(ipad->value);
if (nm)
{
x = nm & 0xFF000000; nm <<= 8;
__COUNTUP (x, pfx, nm);
}
if (nm)
{
x = nm & 0xFF000000; nm <<= 8;
__COUNTUP (x, pfx, nm);
}
if (nm)
{
x = nm & 0xFF000000; nm <<= 8;
__COUNTUP (x, pfx, nm);
}
if (nm)
{
x = nm & 0xFF000000;
__COUNTUP (x, pfx, 0);
}
return pfx;
}
/* TODO: qse_ip6adtoprefix() */