| 56 | |
| 57 | |
| 58 | int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult) |
| 59 | { |
| 60 | // See if we've been given a valid IP address |
| 61 | const char* p =aIPAddrString; |
| 62 | while (*p && |
| 63 | ( (*p == '.') || (*p >= '0') || (*p <= '9') )) |
| 64 | { |
| 65 | p++; |
| 66 | } |
| 67 | |
| 68 | if (*p == '\0') |
| 69 | { |
| 70 | // It's looking promising, we haven't found any invalid characters |
| 71 | p = aIPAddrString; |
| 72 | int segment =0; |
| 73 | int segmentValue =0; |
| 74 | while (*p && (segment < 4)) |
| 75 | { |
| 76 | if (*p == '.') |
| 77 | { |
| 78 | // We've reached the end of a segment |
| 79 | if (segmentValue > 255) |
| 80 | { |
| 81 | // You can't have IP address segments that don't fit in a byte |
| 82 | return 0; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | aResult[segment] = (byte)segmentValue; |
| 87 | segment++; |
| 88 | segmentValue = 0; |
| 89 | } |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | // Next digit |
| 94 | segmentValue = (segmentValue*10)+(*p - '0'); |
| 95 | } |
| 96 | p++; |
| 97 | } |
| 98 | // We've reached the end of address, but there'll still be the last |
| 99 | // segment to deal with |
| 100 | if ((segmentValue > 255) || (segment > 3)) |
| 101 | { |
| 102 | // You can't have IP address segments that don't fit in a byte, |
| 103 | // or more than four segments |
| 104 | return 0; |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | aResult[segment] = (byte)segmentValue; |
| 109 | return 1; |
| 110 | } |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | return 0; |
| 115 | } |
nothing calls this directly
no outgoing calls
no test coverage detected