47 unsigned int a,
b,
ip;
49 switch (
range->type) {
53 return !memcmp(&
range->a, addr,
sizeof(
range->a));
76 return !((
ip &
b) ^
a);
99 memset(&retval, 0,
sizeof(retval));
138 static size_t x_size(
const char* dst,
size_t len,
const char* ptr)
140 return len > (size_t)(ptr - dst) ?
len - (size_t)(ptr - dst) : 0;
163 switch (
range->type) {
166 memcpy(s,
"Host", 4);
172 memcpy(s,
"Range", 5);
177 memcpy(s,
"Network", 7);
193 sprintf(s,
"/%u", temp.
b);
218 unsigned int addr, temp;
242 if (*p++ ==
'/' && !
isspace((
unsigned char)(*p))) {
244 d = strtol(p, &e, 10);
245 if (!errno && p != e && !*e && d > 0) {
247 if (ipv4 && d <= 32) {
254 temp = (
unsigned int)(~0UL << (32 - d));
257 return addr && !(addr & ~temp);
259 && (
size_t) d <= (
sizeof(
range->a.octet) << 3)) {
260 if (!d || (
size_t) d == (
sizeof(
range->a.octet) << 3)) {
269 d = (long)(
sizeof(
range->a.octet) << 3) - d;
271 for (
n =
sizeof(
range->a.octet);
n > 0; --
n) {
273 if (
range->a.octet[
n - 1] & ~0)
277 if (
range->a.octet[
n - 1] & ~(~0 << d))
304 d = strtol(p, &e, 10);
305 if (errno || p == e || e - p > 3 || d < 0 || 255 < d
306 || sprintf(s,
"%u", (
unsigned int) d) != (
int)(e - p)) {
310 }
else if (!*++p && dots) {
311 temp = (
unsigned int)((4 - dots) << 3);
319 switch (
range->type) {
322 addr |= (
unsigned int) d;
324 addr <<= (3 - dots) << 3;
336 }
else if (++dots <= 3) {
351 return !(temp & (temp + 1)) && addr && !(addr & temp);
355 temp = dots > 0 ? addr : 0;
356 temp &= (
unsigned int)(~((1UL << ((4 - dots) << 3)) - 1));
357 temp |= (
unsigned int) (d << ((3 - dots) << 3));
358 temp |= (
unsigned int) ((1U << ((3 - dots) << 3)) - 1);
376 temp = (
unsigned int)(~0UL << (32 - d));
378 return addr && !(addr & ~temp);
std::ofstream out("events_result.xml")
main entry point for tests
int SOCK_isipEx(const char *host, int fullquad)
Check whether the given string represents a valid IPv4 address.
unsigned int SOCK_HostToNetLong(unsigned int value)
See man for the BSDisms, htonl() and htons().
#define SOCK_NetToHostLong
unsigned int SOCK_gethostbyname(const char *hostname)
Same as SOCK_gethostbynameEx(,<current API data logging>)
int SOCK_ntoa(unsigned int addr, char *buf, size_t bufsize)
Convert IP address to a string in dotted notation.
int SOCK_isip(const char *host)
Equivalent of SOCK_isip(host, 0)
unsigned int
A callback function used to compare two keys in a database.
range(_Ty, _Ty) -> range< _Ty >
char * strncpy0(char *s1, const char *s2, size_t n)
Copy not more than "n" characters from string "s2" into "s1", and return the result,...
SIPRange NcbiTrueIPRange(const SIPRange *range)
int NcbiIsInIPRange(const SIPRange *range, const TNCBI_IPv6Addr *addr)
const char * NcbiDumpIPRange(const SIPRange *range, char *buf, size_t bufsize)
static size_t x_size(const char *dst, size_t len, const char *ptr)
int NcbiParseIPRange(SIPRange *range, const char *str)
Acceptable forms (netmasked IPv4s may omit trailing .0s before '/'): 4 quad full IP: 123....
int NcbiIsEmptyIPv6(const TNCBI_IPv6Addr *addr)
Return non-zero if the address is empty (either as IPv6 or IPv4); return zero otherwise.
const char * NcbiDNSIPToAddr(TNCBI_IPv6Addr *addr, const char *str, size_t len)
Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str",...
unsigned int NcbiIPv6ToIPv4(const TNCBI_IPv6Addr *addr, size_t pfxlen)
Extract and return a network byte order IPv4 embedded address from an IPv6 address,...
char * NcbiIPv6ToString(char *buf, size_t bufsize, const TNCBI_IPv6Addr *addr)
Convert an IPv6 address into a hex colon-separated text form and store the result in the "buf" of siz...
int NcbiIsIPv4(const TNCBI_IPv6Addr *addr)
Return non-zero(true) if the address is a true IPv4 address (a mapped IPv4 address); return zero(fals...
const char * NcbiStringToIPv4(unsigned int *addr, const char *str, size_t len)
Convert into a network byte order IPv4 address, the first "len" (or "strlen(str)" if "len" is 0) byte...
int NcbiIsInIPv6Network(const TNCBI_IPv6Addr *base, unsigned int bits, const TNCBI_IPv6Addr *addr)
Return non-zero(true) if "addr" belongs to the network specified as CIDR "base/bits"; return a zero(f...
int NcbiIPv4ToIPv6(TNCBI_IPv6Addr *addr, unsigned int ipv4, size_t pfxlen)
Embed a passed network byte order IPv4 address into an IPv6 address using the specified prefix length...
const char * NcbiIPToAddr(TNCBI_IPv6Addr *addr, const char *str, size_t len)
Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from ei...
static const char * str(char *buf, int n)