Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: webrtc/base/winping.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/winping.h ('k') | webrtc/base/x11windowpicker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Global Constants and Types 119 // Global Constants and Types
120 ////////////////////////////////////////////////////////////////////// 120 //////////////////////////////////////////////////////////////////////
121 121
122 const char * const ICMP_DLL_NAME = "Iphlpapi.dll"; 122 const char * const ICMP_DLL_NAME = "Iphlpapi.dll";
123 const char * const ICMP_CREATE_FUNC = "IcmpCreateFile"; 123 const char * const ICMP_CREATE_FUNC = "IcmpCreateFile";
124 const char * const ICMP_CLOSE_FUNC = "IcmpCloseHandle"; 124 const char * const ICMP_CLOSE_FUNC = "IcmpCloseHandle";
125 const char * const ICMP_SEND_FUNC = "IcmpSendEcho"; 125 const char * const ICMP_SEND_FUNC = "IcmpSendEcho";
126 const char * const ICMP6_CREATE_FUNC = "Icmp6CreateFile"; 126 const char * const ICMP6_CREATE_FUNC = "Icmp6CreateFile";
127 const char * const ICMP6_SEND_FUNC = "Icmp6SendEcho2"; 127 const char * const ICMP6_SEND_FUNC = "Icmp6SendEcho2";
128 128
129 inline uint32 ReplySize(uint32 data_size, int family) { 129 inline uint32_t ReplySize(uint32_t data_size, int family) {
130 if (family == AF_INET) { 130 if (family == AF_INET) {
131 // A ping error message is 8 bytes long, so make sure we allow for at least 131 // A ping error message is 8 bytes long, so make sure we allow for at least
132 // 8 bytes of reply data. 132 // 8 bytes of reply data.
133 return sizeof(ICMP_ECHO_REPLY) + std::max<uint32>(8, data_size); 133 return sizeof(ICMP_ECHO_REPLY) + std::max<uint32_t>(8, data_size);
134 } else if (family == AF_INET6) { 134 } else if (family == AF_INET6) {
135 // Per MSDN, Send6IcmpEcho2 needs at least one ICMPV6_ECHO_REPLY, 135 // Per MSDN, Send6IcmpEcho2 needs at least one ICMPV6_ECHO_REPLY,
136 // 8 bytes for ICMP header, _and_ an IO_BLOCK_STATUS (2 pointers), 136 // 8 bytes for ICMP header, _and_ an IO_BLOCK_STATUS (2 pointers),
137 // in addition to the data size. 137 // in addition to the data size.
138 return sizeof(ICMPV6_ECHO_REPLY) + data_size + 8 + (2 * sizeof(DWORD*)); 138 return sizeof(ICMPV6_ECHO_REPLY) + data_size + 8 + (2 * sizeof(DWORD*));
139 } else { 139 } else {
140 return 0; 140 return 0;
141 } 141 }
142 } 142 }
143 143
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 201 }
202 } 202 }
203 203
204 if (dll_) 204 if (dll_)
205 FreeLibrary(dll_); 205 FreeLibrary(dll_);
206 206
207 delete[] data_; 207 delete[] data_;
208 delete[] reply_; 208 delete[] reply_;
209 } 209 }
210 210
211 WinPing::PingResult WinPing::Ping( 211 WinPing::PingResult WinPing::Ping(IPAddress ip,
212 IPAddress ip, uint32 data_size, uint32 timeout, uint8 ttl, 212 uint32_t data_size,
213 bool allow_fragments) { 213 uint32_t timeout,
214 214 uint8_t ttl,
215 bool allow_fragments) {
215 if (data_size == 0 || timeout == 0 || ttl == 0) { 216 if (data_size == 0 || timeout == 0 || ttl == 0) {
216 LOG(LERROR) << "IcmpSendEcho: data_size/timeout/ttl is 0."; 217 LOG(LERROR) << "IcmpSendEcho: data_size/timeout/ttl is 0.";
217 return PING_INVALID_PARAMS; 218 return PING_INVALID_PARAMS;
218 } 219 }
219 220
220 assert(IsValid()); 221 assert(IsValid());
221 222
222 IP_OPTION_INFORMATION ipopt; 223 IP_OPTION_INFORMATION ipopt;
223 memset(&ipopt, 0, sizeof(ipopt)); 224 memset(&ipopt, 0, sizeof(ipopt));
224 if (!allow_fragments) 225 if (!allow_fragments)
225 ipopt.Flags |= IP_FLAG_DF; 226 ipopt.Flags |= IP_FLAG_DF;
226 ipopt.Ttl = ttl; 227 ipopt.Ttl = ttl;
227 228
228 uint32 reply_size = ReplySize(data_size, ip.family()); 229 uint32_t reply_size = ReplySize(data_size, ip.family());
229 230
230 if (data_size > dlen_) { 231 if (data_size > dlen_) {
231 delete [] data_; 232 delete [] data_;
232 dlen_ = data_size; 233 dlen_ = data_size;
233 data_ = new char[dlen_]; 234 data_ = new char[dlen_];
234 memset(data_, 'z', dlen_); 235 memset(data_, 'z', dlen_);
235 } 236 }
236 237
237 if (reply_size > rlen_) { 238 if (reply_size > rlen_) {
238 delete [] reply_; 239 delete [] reply_;
239 rlen_ = reply_size; 240 rlen_ = reply_size;
240 reply_ = new char[rlen_]; 241 reply_ = new char[rlen_];
241 } 242 }
242 DWORD result = 0; 243 DWORD result = 0;
243 if (ip.family() == AF_INET) { 244 if (ip.family() == AF_INET) {
244 result = send_(hping_, ip.ipv4_address().S_un.S_addr, 245 result = send_(hping_, ip.ipv4_address().S_un.S_addr, data_,
245 data_, uint16(data_size), &ipopt, 246 uint16_t(data_size), &ipopt, reply_, reply_size, timeout);
246 reply_, reply_size, timeout);
247 } else if (ip.family() == AF_INET6) { 247 } else if (ip.family() == AF_INET6) {
248 sockaddr_in6 src = {0}; 248 sockaddr_in6 src = {0};
249 sockaddr_in6 dst = {0}; 249 sockaddr_in6 dst = {0};
250 src.sin6_family = AF_INET6; 250 src.sin6_family = AF_INET6;
251 dst.sin6_family = AF_INET6; 251 dst.sin6_family = AF_INET6;
252 dst.sin6_addr = ip.ipv6_address(); 252 dst.sin6_addr = ip.ipv6_address();
253 result = send6_(hping6_, NULL, NULL, NULL, 253 result = send6_(hping6_, NULL, NULL, NULL, &src, &dst, data_,
254 &src, &dst, 254 int16_t(data_size), &ipopt, reply_, reply_size, timeout);
255 data_, int16(data_size), &ipopt,
256 reply_, reply_size, timeout);
257 } 255 }
258 if (result == 0) { 256 if (result == 0) {
259 DWORD error = GetLastError(); 257 DWORD error = GetLastError();
260 if (error == IP_PACKET_TOO_BIG) 258 if (error == IP_PACKET_TOO_BIG)
261 return PING_TOO_LARGE; 259 return PING_TOO_LARGE;
262 if (error == IP_REQ_TIMED_OUT) 260 if (error == IP_REQ_TIMED_OUT)
263 return PING_TIMEOUT; 261 return PING_TIMEOUT;
264 LOG(LERROR) << "IcmpSendEcho(" << ip.ToSensitiveString() 262 LOG(LERROR) << "IcmpSendEcho(" << ip.ToSensitiveString()
265 << ", " << data_size << "): " << error; 263 << ", " << data_size << "): " << error;
266 return PING_FAIL; 264 return PING_FAIL;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Return Value: 349 // Return Value:
352 // 350 //
353 // Returns the number of ICMP_ECHO_REPLY structures stored in ReplyBuffer. 351 // Returns the number of ICMP_ECHO_REPLY structures stored in ReplyBuffer.
354 // The status of each reply is contained in the structure. If the return 352 // The status of each reply is contained in the structure. If the return
355 // value is zero, extended error information is available via 353 // value is zero, extended error information is available via
356 // GetLastError(). 354 // GetLastError().
357 // 355 //
358 ////////////////////////////////////////////////////////////////////// 356 //////////////////////////////////////////////////////////////////////
359 357
360 } // namespace rtc 358 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/winping.h ('k') | webrtc/base/x11windowpicker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698