OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 as_in_addr->S_un.S_un_b.s_b3, | 75 as_in_addr->S_un.S_un_b.s_b3, |
76 as_in_addr->S_un.S_un_b.s_b4); | 76 as_in_addr->S_un.S_un_b.s_b4); |
77 return dst; | 77 return dst; |
78 } | 78 } |
79 | 79 |
80 // Helper function for inet_ntop for IPv6 addresses. | 80 // Helper function for inet_ntop for IPv6 addresses. |
81 const char* inet_ntop_v6(const void* src, char* dst, socklen_t size) { | 81 const char* inet_ntop_v6(const void* src, char* dst, socklen_t size) { |
82 if (size < INET6_ADDRSTRLEN) { | 82 if (size < INET6_ADDRSTRLEN) { |
83 return NULL; | 83 return NULL; |
84 } | 84 } |
85 const uint16* as_shorts = | 85 const uint16_t* as_shorts = reinterpret_cast<const uint16_t*>(src); |
86 reinterpret_cast<const uint16*>(src); | |
87 int runpos[8]; | 86 int runpos[8]; |
88 int current = 1; | 87 int current = 1; |
89 int max = 0; | 88 int max = 0; |
90 int maxpos = -1; | 89 int maxpos = -1; |
91 int run_array_size = ARRAY_SIZE(runpos); | 90 int run_array_size = ARRAY_SIZE(runpos); |
92 // Run over the address marking runs of 0s. | 91 // Run over the address marking runs of 0s. |
93 for (int i = 0; i < run_array_size; ++i) { | 92 for (int i = 0; i < run_array_size; ++i) { |
94 if (as_shorts[i] == 0) { | 93 if (as_shorts[i] == 0) { |
95 runpos[i] = current; | 94 runpos[i] = current; |
96 if (current > max) { | 95 if (current > max) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (c == 'x') { | 206 if (c == 'x') { |
208 return 0; | 207 return 0; |
209 } | 208 } |
210 c = *readcursor++; | 209 c = *readcursor++; |
211 } | 210 } |
212 readcursor = src; | 211 readcursor = src; |
213 | 212 |
214 struct in6_addr an_addr; | 213 struct in6_addr an_addr; |
215 memset(&an_addr, 0, sizeof(an_addr)); | 214 memset(&an_addr, 0, sizeof(an_addr)); |
216 | 215 |
217 uint16* addr_cursor = reinterpret_cast<uint16*>(&an_addr.s6_addr[0]); | 216 uint16_t* addr_cursor = reinterpret_cast<uint16_t*>(&an_addr.s6_addr[0]); |
218 uint16* addr_end = reinterpret_cast<uint16*>(&an_addr.s6_addr[16]); | 217 uint16_t* addr_end = reinterpret_cast<uint16_t*>(&an_addr.s6_addr[16]); |
219 bool seencompressed = false; | 218 bool seencompressed = false; |
220 | 219 |
221 // Addresses that start with "::" (i.e., a run of initial zeros) or | 220 // Addresses that start with "::" (i.e., a run of initial zeros) or |
222 // "::ffff:" can potentially be IPv4 mapped or compatibility addresses. | 221 // "::ffff:" can potentially be IPv4 mapped or compatibility addresses. |
223 // These have dotted-style IPv4 addresses on the end (e.g. "::192.168.7.1"). | 222 // These have dotted-style IPv4 addresses on the end (e.g. "::192.168.7.1"). |
224 if (*readcursor == ':' && *(readcursor+1) == ':' && | 223 if (*readcursor == ':' && *(readcursor+1) == ':' && |
225 *(readcursor + 2) != 0) { | 224 *(readcursor + 2) != 0) { |
226 // Check for periods, which we'll take as a sign of v4 addresses. | 225 // Check for periods, which we'll take as a sign of v4 addresses. |
227 const char* addrstart = readcursor + 2; | 226 const char* addrstart = readcursor + 2; |
228 if (rtc::strchr(addrstart, ".")) { | 227 if (rtc::strchr(addrstart, ".")) { |
229 const char* colon = rtc::strchr(addrstart, "::"); | 228 const char* colon = rtc::strchr(addrstart, "::"); |
230 if (colon) { | 229 if (colon) { |
231 uint16 a_short; | 230 uint16_t a_short; |
232 int bytesread = 0; | 231 int bytesread = 0; |
233 if (sscanf(addrstart, "%hx%n", &a_short, &bytesread) != 1 || | 232 if (sscanf(addrstart, "%hx%n", &a_short, &bytesread) != 1 || |
234 a_short != 0xFFFF || bytesread != 4) { | 233 a_short != 0xFFFF || bytesread != 4) { |
235 // Colons + periods means has to be ::ffff:a.b.c.d. But it wasn't. | 234 // Colons + periods means has to be ::ffff:a.b.c.d. But it wasn't. |
236 return 0; | 235 return 0; |
237 } else { | 236 } else { |
238 an_addr.s6_addr[10] = 0xFF; | 237 an_addr.s6_addr[10] = 0xFF; |
239 an_addr.s6_addr[11] = 0xFF; | 238 an_addr.s6_addr[11] = 0xFF; |
240 addrstart = colon + 1; | 239 addrstart = colon + 1; |
241 } | 240 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 ++coloncounter; | 275 ++coloncounter; |
277 } | 276 } |
278 // (coloncount + 1) is the number of shorts left in the address. | 277 // (coloncount + 1) is the number of shorts left in the address. |
279 addr_cursor = addr_end - (coloncount + 1); | 278 addr_cursor = addr_end - (coloncount + 1); |
280 seencompressed = true; | 279 seencompressed = true; |
281 } | 280 } |
282 } else { | 281 } else { |
283 ++readcursor; | 282 ++readcursor; |
284 } | 283 } |
285 } else { | 284 } else { |
286 uint16 word; | 285 uint16_t word; |
287 int bytesread = 0; | 286 int bytesread = 0; |
288 if (sscanf(readcursor, "%hx%n", &word, &bytesread) != 1) { | 287 if (sscanf(readcursor, "%hx%n", &word, &bytesread) != 1) { |
289 return 0; | 288 return 0; |
290 } else { | 289 } else { |
291 *addr_cursor = HostToNetwork16(word); | 290 *addr_cursor = HostToNetwork16(word); |
292 ++addr_cursor; | 291 ++addr_cursor; |
293 readcursor += bytesread; | 292 readcursor += bytesread; |
294 if (*readcursor != ':' && *readcursor != '\0') { | 293 if (*readcursor != ':' && *readcursor != '\0') { |
295 return 0; | 294 return 0; |
296 } | 295 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 FILETIME base_ft; | 354 FILETIME base_ft; |
356 SystemTimeToFileTime(&base_st, &base_ft); | 355 SystemTimeToFileTime(&base_st, &base_ft); |
357 | 356 |
358 ULARGE_INTEGER base_ul; | 357 ULARGE_INTEGER base_ul; |
359 memcpy(&base_ul, &base_ft, sizeof(FILETIME)); | 358 memcpy(&base_ul, &base_ft, sizeof(FILETIME)); |
360 | 359 |
361 // Multiply by big number to convert to 100ns units, then add in the 1970 | 360 // Multiply by big number to convert to 100ns units, then add in the 1970 |
362 // base date value. | 361 // base date value. |
363 const ULONGLONG RATIO = 10000000; | 362 const ULONGLONG RATIO = 10000000; |
364 ULARGE_INTEGER current_ul; | 363 ULARGE_INTEGER current_ul; |
365 current_ul.QuadPart = base_ul.QuadPart + static_cast<int64>(ut) * RATIO; | 364 current_ul.QuadPart = base_ul.QuadPart + static_cast<int64_t>(ut) * RATIO; |
366 memcpy(ft, ¤t_ul, sizeof(FILETIME)); | 365 memcpy(ft, ¤t_ul, sizeof(FILETIME)); |
367 } | 366 } |
368 | 367 |
369 bool Utf8ToWindowsFilename(const std::string& utf8, std::wstring* filename) { | 368 bool Utf8ToWindowsFilename(const std::string& utf8, std::wstring* filename) { |
370 // TODO: Integrate into fileutils.h | 369 // TODO: Integrate into fileutils.h |
371 // TODO: Handle wide and non-wide cases via TCHAR? | 370 // TODO: Handle wide and non-wide cases via TCHAR? |
372 // TODO: Skip \\?\ processing if the length is not > MAX_PATH? | 371 // TODO: Skip \\?\ processing if the length is not > MAX_PATH? |
373 // TODO: Write unittests | 372 // TODO: Write unittests |
374 | 373 |
375 // Convert to Utf16 | 374 // Convert to Utf16 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 *level = *GetSidSubAuthority(til->Label.Sid, count - 1); | 447 *level = *GetSidSubAuthority(til->Label.Sid, count - 1); |
449 ret = true; | 448 ret = true; |
450 } | 449 } |
451 } | 450 } |
452 CloseHandle(token); | 451 CloseHandle(token); |
453 } | 452 } |
454 return ret; | 453 return ret; |
455 } | 454 } |
456 | 455 |
457 } // namespace rtc | 456 } // namespace rtc |
OLD | NEW |