| 475 | } |
| 476 | |
| 477 | const 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 | |
| 496 | const char *atoipr(const char *s, iprange *ir) |
| 497 | { |
no test coverage detected