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 #include "content/browser/renderer_host/p2p/socket_host.h" | 5 #include "content/browser/renderer_host/p2p/socket_host.h" |
6 | 6 |
7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" | 9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_udp.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 P2PSocketHost::~P2PSocketHost() { } | 27 P2PSocketHost::~P2PSocketHost() { } |
28 | 28 |
29 // Verifies that the packet |data| has a valid STUN header. | 29 // Verifies that the packet |data| has a valid STUN header. |
30 // static | 30 // static |
31 bool P2PSocketHost::GetStunPacketType( | 31 bool P2PSocketHost::GetStunPacketType( |
32 const char* data, int data_size, StunMessageType* type) { | 32 const char* data, int data_size, StunMessageType* type) { |
33 | 33 |
34 if (data_size < kStunHeaderSize) | 34 if (data_size < kStunHeaderSize) |
35 return false; | 35 return false; |
36 | 36 |
37 uint32 cookie = ntohl(*reinterpret_cast<const uint32*>(data + 4)); | 37 uint32 cookie = base::NetToHost32(*reinterpret_cast<const uint32*>(data + 4)); |
38 if (cookie != kStunMagicCookie) | 38 if (cookie != kStunMagicCookie) |
39 return false; | 39 return false; |
40 | 40 |
41 uint16 length = ntohs(*reinterpret_cast<const uint16*>(data + 2)); | 41 uint16 length = base::NetToHost16(*reinterpret_cast<const uint16*>(data + 2)); |
42 if (length != data_size - kStunHeaderSize) | 42 if (length != data_size - kStunHeaderSize) |
43 return false; | 43 return false; |
44 | 44 |
45 int message_type = ntohs(*reinterpret_cast<const uint16*>(data)); | 45 int message_type = base::NetToHost16(*reinterpret_cast<const uint16*>(data)); |
46 | 46 |
47 // Verify that the type is known: | 47 // Verify that the type is known: |
48 switch (message_type) { | 48 switch (message_type) { |
49 case STUN_BINDING_REQUEST: | 49 case STUN_BINDING_REQUEST: |
50 case STUN_BINDING_RESPONSE: | 50 case STUN_BINDING_RESPONSE: |
51 case STUN_BINDING_ERROR_RESPONSE: | 51 case STUN_BINDING_ERROR_RESPONSE: |
52 case STUN_SHARED_SECRET_REQUEST: | 52 case STUN_SHARED_SECRET_REQUEST: |
53 case STUN_SHARED_SECRET_RESPONSE: | 53 case STUN_SHARED_SECRET_RESPONSE: |
54 case STUN_SHARED_SECRET_ERROR_RESPONSE: | 54 case STUN_SHARED_SECRET_ERROR_RESPONSE: |
55 case STUN_ALLOCATE_REQUEST: | 55 case STUN_ALLOCATE_REQUEST: |
(...skipping 30 matching lines...) Expand all Loading... |
86 | 86 |
87 case P2P_SOCKET_TCP_CLIENT: | 87 case P2P_SOCKET_TCP_CLIENT: |
88 return new P2PSocketHostTcp(message_sender, routing_id, id); | 88 return new P2PSocketHostTcp(message_sender, routing_id, id); |
89 } | 89 } |
90 | 90 |
91 NOTREACHED(); | 91 NOTREACHED(); |
92 return NULL; | 92 return NULL; |
93 } | 93 } |
94 | 94 |
95 } // namespace content | 95 } // namespace content |
OLD | NEW |