MCPcopy Create free account
hub / github.com/assaultcube/AC / atoip

Function atoip

source/src/tools.cpp:477–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

475}
476
477const char *atoip(const char *s, enet_uint32 *ip)
478{
479 unsigned int d[4];
480 int n;
481 if(!s) return NULL;
482 if(sscanf(s, "%u.%u.%u.%u%n", d, d + 1, d + 2, d + 3, &n) != 4)
483 {
484 *ip = strtoul(s, (char **)&s, 0); // try single-integer IPs
485 return *ip > 0xffffff ? s : NULL; // require first octet to be non-zero to avoid misinterpreting faulty dotted IPs
486 }
487 *ip = 0;
488 loopi(4)
489 {
490 if(d[i] > 255) return NULL;
491 *ip = (*ip << 8) + d[i];
492 }
493 return s + n;
494}
495
496const char *atoipr(const char *s, iprange *ir)
497{

Callers 2

atoiprFunction · 0.85
parsevitasFunction · 0.85

Calls 1

loopiFunction · 0.70

Tested by

no test coverage detected