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,39 @@ |
} |
// 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* src_pos = src; |
+ unsigned char result[4]; |
Sergey Ulanov
2012/02/29 05:30:31
Might be better to define const kIpv4AddressSize =
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ memset(result, 0, sizeof(result)); |
tommi (sloooow) - chröme
2012/02/29 09:54:22
nit: instead of memset, you can just do:
unsigned
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ |
+ while (*src_pos != 0) { |
Sergey Ulanov
2012/02/29 05:30:31
can replace this with a for loop from 0 to 3, that
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
I tried to do that be it seems that won't save muc
|
+ if (*src_pos < '0' || *src_pos > '9') |
Sergey Ulanov
2012/02/29 05:30:31
nit: add a comment explaining why we need it.
Sergey Ulanov
2012/02/29 05:30:31
use isdigit()
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ return 0; |
+ char* end_pos; |
+ long int value = strtol(src_pos, &end_pos, 10); |
+ if (value < 0 || value > 255 || |
+ src_pos == end_pos) |
Sergey Ulanov
2012/02/29 05:30:31
nit: no need to wrap this line. move this conditio
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ return 0; |
+ result[num_dot] = value; |
+ if (*end_pos == 0) |
+ break; |
+ src_pos = end_pos; |
+ if (*src_pos == '.') { |
+ if (++num_dot > 3) |
Sergey Ulanov
2012/02/29 05:30:31
move increment out of the if condition:
++num_dot
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ return 0; |
+ } |
+ ++src_pos; |
+ } |
+ 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); |
Sergey Ulanov
2012/02/29 05:30:31
s/4/sizeof(result)/
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
return 1; |
} |