| 37 | #include <netinet/in.h> |
| 38 | |
| 39 | int |
| 40 | inet_aton(const char *cp, struct in_addr *addr) |
| 41 | { |
| 42 | u_long parts[4]; |
| 43 | in_addr_t val; |
| 44 | const char *c; |
| 45 | char *endptr; |
| 46 | int gotend, n; |
| 47 | |
| 48 | c = (const char *)cp; |
| 49 | n = 0; |
| 50 | |
| 51 | /* |
| 52 | * Run through the string, grabbing numbers until |
| 53 | * the end of the string, or some error |
| 54 | */ |
| 55 | gotend = 0; |
| 56 | while (!gotend) { |
| 57 | unsigned long l; |
| 58 | |
| 59 | l = strtoul(c, &endptr, 0); |
| 60 | |
| 61 | if (l == ULONG_MAX || (l == 0 && endptr == c)) |
| 62 | return (0); |
| 63 | |
| 64 | val = (in_addr_t)l; |
| 65 | |
| 66 | /* |
| 67 | * If the whole string is invalid, endptr will equal |
| 68 | * c.. this way we can make sure someone hasn't |
| 69 | * gone '.12' or something which would get past |
| 70 | * the next check. |
| 71 | */ |
| 72 | if (endptr == c) |
| 73 | return (0); |
| 74 | parts[n] = val; |
| 75 | c = endptr; |
| 76 | |
| 77 | /* Check the next character past the previous number's end */ |
| 78 | switch (*c) { |
| 79 | case '.' : |
| 80 | |
| 81 | /* Make sure we only do 3 dots .. */ |
| 82 | if (n == 3) /* Whoops. Quit. */ |
| 83 | return (0); |
| 84 | n++; |
| 85 | c++; |
| 86 | break; |
| 87 | |
| 88 | case '\0': |
| 89 | gotend = 1; |
| 90 | break; |
| 91 | |
| 92 | default: |
| 93 | if (isspace((unsigned char)*c)) { |
| 94 | gotend = 1; |
| 95 | break; |
| 96 | } else { |
no test coverage detected