OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/quic/quic_socket_address_coder.h" | 5 #include "net/quic/quic_socket_address_coder.h" |
6 | 6 |
7 #include "net/base/sys_addrinfo.h" | 7 #include "net/base/sys_addrinfo.h" |
8 | 8 |
9 using std::string; | 9 using std::string; |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 address_family = kIPv4; | 34 address_family = kIPv4; |
35 break; | 35 break; |
36 case AF_INET6: | 36 case AF_INET6: |
37 address_family = kIPv6; | 37 address_family = kIPv6; |
38 break; | 38 break; |
39 default: | 39 default: |
40 return serialized; | 40 return serialized; |
41 } | 41 } |
42 serialized.append(reinterpret_cast<const char*>(&address_family), | 42 serialized.append(reinterpret_cast<const char*>(&address_family), |
43 sizeof(address_family)); | 43 sizeof(address_family)); |
44 serialized.append(IPAddressToPackedString(address_.address())); | 44 serialized.append(IPAddressToPackedString(address_.address().bytes())); |
45 uint16_t port = address_.port(); | 45 uint16_t port = address_.port(); |
46 serialized.append(reinterpret_cast<const char*>(&port), sizeof(port)); | 46 serialized.append(reinterpret_cast<const char*>(&port), sizeof(port)); |
47 return serialized; | 47 return serialized; |
48 } | 48 } |
49 | 49 |
50 bool QuicSocketAddressCoder::Decode(const char* data, size_t length) { | 50 bool QuicSocketAddressCoder::Decode(const char* data, size_t length) { |
51 uint16_t address_family; | 51 uint16_t address_family; |
52 if (length < sizeof(address_family)) { | 52 if (length < sizeof(address_family)) { |
53 return false; | 53 return false; |
54 } | 54 } |
(...skipping 24 matching lines...) Expand all Loading... |
79 if (length != sizeof(port)) { | 79 if (length != sizeof(port)) { |
80 return false; | 80 return false; |
81 } | 81 } |
82 memcpy(&port, data, length); | 82 memcpy(&port, data, length); |
83 | 83 |
84 address_ = IPEndPoint(ip, port); | 84 address_ = IPEndPoint(ip, port); |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 } // namespace net | 88 } // namespace net |
OLD | NEW |