| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 (*packet)[i] = rand() % 256; | 189 (*packet)[i] = rand() % 256; |
| 190 } | 190 } |
| 191 // Always set the first bit to ensure that generated packet is not | 191 // Always set the first bit to ensure that generated packet is not |
| 192 // valid STUN packet. | 192 // valid STUN packet. |
| 193 (*packet)[0] = (*packet)[0] | 0x80; | 193 (*packet)[0] = (*packet)[0] | 0x80; |
| 194 } | 194 } |
| 195 | 195 |
| 196 static void CreateStunPacket(std::vector<char>* packet, uint16 type) { | 196 static void CreateStunPacket(std::vector<char>* packet, uint16 type) { |
| 197 CreateRandomPacket(packet); | 197 CreateRandomPacket(packet); |
| 198 *reinterpret_cast<uint16*>(&*packet->begin()) = base::HostToNet16(type); | 198 *reinterpret_cast<uint16*>(&*packet->begin()) = base::HostToNet16(type); |
| 199 *reinterpret_cast<uint16*>(&*packet->begin() + 2) = | 199 *reinterpret_cast<uint16*>(&*packet->begin() + 2) = base::HostToNet16( |
| 200 base::HostToNet16(packet->size() - kStunHeaderSize); | 200 base::checked_cast<uint16>(packet->size() - kStunHeaderSize)); |
| 201 *reinterpret_cast<uint32*>(&*packet->begin() + 4) = | 201 *reinterpret_cast<uint32*>(&*packet->begin() + 4) = |
| 202 base::HostToNet32(kStunMagicCookie); | 202 base::HostToNet32(kStunMagicCookie); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void CreateStunRequest(std::vector<char>* packet) { | 205 void CreateStunRequest(std::vector<char>* packet) { |
| 206 CreateStunPacket(packet, kStunBindingRequest); | 206 CreateStunPacket(packet, kStunBindingRequest); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void CreateStunResponse(std::vector<char>* packet) { | 209 void CreateStunResponse(std::vector<char>* packet) { |
| 210 CreateStunPacket(packet, kStunBindingResponse); | 210 CreateStunPacket(packet, kStunBindingResponse); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void CreateStunError(std::vector<char>* packet) { | 213 void CreateStunError(std::vector<char>* packet) { |
| 214 CreateStunPacket(packet, kStunBindingError); | 214 CreateStunPacket(packet, kStunBindingError); |
| 215 } | 215 } |
| 216 | 216 |
| 217 net::IPEndPoint ParseAddress(const std::string& ip_str, uint16 port) { | 217 net::IPEndPoint ParseAddress(const std::string& ip_str, uint16 port) { |
| 218 net::IPAddressNumber ip; | 218 net::IPAddressNumber ip; |
| 219 EXPECT_TRUE(net::ParseIPLiteralToNumber(ip_str, &ip)); | 219 EXPECT_TRUE(net::ParseIPLiteralToNumber(ip_str, &ip)); |
| 220 return net::IPEndPoint(ip, port); | 220 return net::IPEndPoint(ip, port); |
| 221 } | 221 } |
| OLD | NEW |