Chromium Code Reviews| Index: third_party/libjingle/overrides/talk/base/win32.cc |
| =================================================================== |
| --- third_party/libjingle/overrides/talk/base/win32.cc (revision 124023) |
| +++ third_party/libjingle/overrides/talk/base/win32.cc (working copy) |
| @@ -172,14 +172,37 @@ |
| } |
| // Helper function for inet_pton for IPv4 addresses. |
| -// Uses win32's inet_addr. |
| +// |src| points to a character string containing an IPv4 network address in |
| +// dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is a decimal number |
| +// of up to three digits in the range 0 to 255. |
| +// The address is converted and copied to dst, |
| +// which must be sizeof(struct in_addr) (4) bytes (32 bits) long. |
| int inet_pton_v4(const char* src, void* dst) { |
| - uint32 ip = inet_addr(src); |
| - if (ip == 0xFFFFFFFF && strcmp(src, "255.255.255.255") != 0) { |
| + int num_dot = 0; |
| + const char* readcursor = src; |
|
Sergey Ulanov
2012/02/28 21:54:02
nit: read_cursor? or maybe src_pos?
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
Done.
|
| + unsigned char result[4]; |
| + memset(result, 0, sizeof(result)); |
| + |
| + while (*readcursor != 0) { |
| + char current = *readcursor; |
| + if (current == '.') { |
|
Sergey Ulanov
2012/02/28 21:54:02
looks like this will accept "2...10" as a valid ad
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
Done.
|
| + if (++num_dot > 3) |
| + return 0; |
| + } else if (current >= '0' && current <= '9') { |
| + int new_value = result[num_dot] * 10 + (current - '0'); |
|
Sergey Ulanov
2012/02/28 21:54:02
Why do you need to parse the numbers yourself? may
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
Done.
|
| + if (new_value > 255) { |
| + return 0; |
| + } |
| + result[num_dot] = new_value; |
| + } else { |
| + return 0; |
| + } |
| + ++readcursor; |
| + } |
| + if (num_dot != 3) { |
| return 0; |
| } |
| - struct in_addr* dst_as_in_addr = reinterpret_cast<struct in_addr*>(dst); |
| - dst_as_in_addr->s_addr = ip; |
| + memcpy(dst, result, 4); |
| return 1; |
| } |