OLD | NEW |
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 Loading... |
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 Loading... |
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, ¶ms); | 277 arg, ¶ms); |
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_ |
OLD | NEW |