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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_test_utils.h

Issue 9716020: Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc ('k') | crypto/encryptor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 for (size_t i = 0; i < size; i++) { 225 for (size_t i = 0; i < size; i++) {
226 (*packet)[i] = rand() % 256; 226 (*packet)[i] = rand() % 256;
227 } 227 }
228 // Always set the first bit to ensure that generated packet is not 228 // Always set the first bit to ensure that generated packet is not
229 // valid STUN packet. 229 // valid STUN packet.
230 (*packet)[0] = (*packet)[0] | 0x80; 230 (*packet)[0] = (*packet)[0] | 0x80;
231 } 231 }
232 232
233 void CreateStunPacket(std::vector<char>* packet, uint16 type) { 233 void CreateStunPacket(std::vector<char>* packet, uint16 type) {
234 CreateRandomPacket(packet); 234 CreateRandomPacket(packet);
235 *reinterpret_cast<uint16*>(&*packet->begin()) = htons(type); 235 *reinterpret_cast<uint16*>(&*packet->begin()) = base::HostToNet16(type);
236 *reinterpret_cast<uint16*>(&*packet->begin() + 2) = 236 *reinterpret_cast<uint16*>(&*packet->begin() + 2) =
237 htons(packet->size() - kStunHeaderSize); 237 base::HostToNet16(packet->size() - kStunHeaderSize);
238 *reinterpret_cast<uint32*>(&*packet->begin() + 4) = htonl(kStunMagicCookie); 238 *reinterpret_cast<uint32*>(&*packet->begin() + 4) =
239 base::HostToNet32(kStunMagicCookie);
239 } 240 }
240 241
241 void CreateStunRequest(std::vector<char>* packet) { 242 void CreateStunRequest(std::vector<char>* packet) {
242 CreateStunPacket(packet, kStunBindingRequest); 243 CreateStunPacket(packet, kStunBindingRequest);
243 } 244 }
244 245
245 void CreateStunResponse(std::vector<char>* packet) { 246 void CreateStunResponse(std::vector<char>* packet) {
246 CreateStunPacket(packet, kStunBindingResponse); 247 CreateStunPacket(packet, kStunBindingResponse);
247 } 248 }
248 249
(...skipping 24 matching lines...) Expand all
273 return false; 274 return false;
274 P2PMsg_OnIncomingTcpConnection::Param params; 275 P2PMsg_OnIncomingTcpConnection::Param params;
275 P2PMsg_OnIncomingTcpConnection::Read( 276 P2PMsg_OnIncomingTcpConnection::Read(
276 arg, &params); 277 arg, &params);
277 return params.b == address; 278 return params.b == address;
278 } 279 }
279 280
280 } // namespace 281 } // namespace
281 282
282 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_ 283 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc ('k') | crypto/encryptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698