Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004--2005, Google Inc. | 3 * Copyright 2004--2005, Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 *cursor++ = ':'; | 165 *cursor++ = ':'; |
| 166 *cursor++ = ':'; | 166 *cursor++ = ':'; |
| 167 i += (max - 1); | 167 i += (max - 1); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 return dst; | 171 return dst; |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Helper function for inet_pton for IPv4 addresses. | 174 // Helper function for inet_pton for IPv4 addresses. |
| 175 // Uses win32's inet_addr. | 175 // |src| points to a character string containing an IPv4 network address in |
| 176 // dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is a decimal number | |
| 177 // of up to three digits in the range 0 to 255. | |
| 178 // The address is converted and copied to dst, | |
| 179 // which must be sizeof(struct in_addr) (4) bytes (32 bits) long. | |
| 176 int inet_pton_v4(const char* src, void* dst) { | 180 int inet_pton_v4(const char* src, void* dst) { |
| 177 uint32 ip = inet_addr(src); | 181 int num_dot = 0; |
| 178 if (ip == 0xFFFFFFFF && strcmp(src, "255.255.255.255") != 0) { | 182 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.
| |
| 183 unsigned char result[4]; | |
| 184 memset(result, 0, sizeof(result)); | |
| 185 | |
| 186 while (*readcursor != 0) { | |
| 187 char current = *readcursor; | |
| 188 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.
| |
| 189 if (++num_dot > 3) | |
| 190 return 0; | |
| 191 } else if (current >= '0' && current <= '9') { | |
| 192 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.
| |
| 193 if (new_value > 255) { | |
| 194 return 0; | |
| 195 } | |
| 196 result[num_dot] = new_value; | |
| 197 } else { | |
| 198 return 0; | |
| 199 } | |
| 200 ++readcursor; | |
| 201 } | |
| 202 if (num_dot != 3) { | |
| 179 return 0; | 203 return 0; |
| 180 } | 204 } |
| 181 struct in_addr* dst_as_in_addr = reinterpret_cast<struct in_addr*>(dst); | 205 memcpy(dst, result, 4); |
| 182 dst_as_in_addr->s_addr = ip; | |
| 183 return 1; | 206 return 1; |
| 184 } | 207 } |
| 185 | 208 |
| 186 // Helper function for inet_pton for IPv6 addresses. | 209 // Helper function for inet_pton for IPv6 addresses. |
| 187 int inet_pton_v6(const char* src, void* dst) { | 210 int inet_pton_v6(const char* src, void* dst) { |
| 188 // sscanf will pick any other invalid chars up, but it parses 0xnnnn as hex. | 211 // sscanf will pick any other invalid chars up, but it parses 0xnnnn as hex. |
| 189 // Check for literal x in the input string. | 212 // Check for literal x in the input string. |
| 190 const char* readcursor = src; | 213 const char* readcursor = src; |
| 191 char c = *readcursor++; | 214 char c = *readcursor++; |
| 192 while (c) { | 215 while (c) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 DWORD count = *GetSidSubAuthorityCount(til->Label.Sid); | 454 DWORD count = *GetSidSubAuthorityCount(til->Label.Sid); |
| 432 *level = *GetSidSubAuthority(til->Label.Sid, count - 1); | 455 *level = *GetSidSubAuthority(til->Label.Sid, count - 1); |
| 433 ret = true; | 456 ret = true; |
| 434 } | 457 } |
| 435 } | 458 } |
| 436 CloseHandle(token); | 459 CloseHandle(token); |
| 437 } | 460 } |
| 438 return ret; | 461 return ret; |
| 439 } | 462 } |
| 440 } // namespace talk_base | 463 } // namespace talk_base |
| OLD | NEW |