OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "tools/android/common/adb_connection.h" | 5 #include "tools/android/common/adb_connection.h" |
6 | 6 |
7 #include <arpa/inet.h> | 7 #include <arpa/inet.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 int ConnectAdbHostSocket(const char* forward_to) { | 32 int ConnectAdbHostSocket(const char* forward_to) { |
33 // ADB port forward request format: HHHHtcp:port:address. | 33 // ADB port forward request format: HHHHtcp:port:address. |
34 // HHHH is the hexidecimal length of the "tcp:port:address" part. | 34 // HHHH is the hexidecimal length of the "tcp:port:address" part. |
35 const size_t kBufferMaxLength = 30; | 35 const size_t kBufferMaxLength = 30; |
36 const size_t kLengthOfLength = 4; | 36 const size_t kLengthOfLength = 4; |
37 const size_t kAddressMaxLength = kBufferMaxLength - kLengthOfLength; | |
38 | 37 |
39 const char kAddressPrefix[] = { 't', 'c', 'p', ':' }; | 38 const char kAddressPrefix[] = { 't', 'c', 'p', ':' }; |
40 size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to); | 39 size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to); |
41 if (address_length > kBufferMaxLength - kLengthOfLength) { | 40 if (address_length > kBufferMaxLength - kLengthOfLength) { |
42 LOG(ERROR) << "Forward to address is too long: " << forward_to; | 41 LOG(ERROR) << "Forward to address is too long: " << forward_to; |
43 return -1; | 42 return -1; |
44 } | 43 } |
45 | 44 |
46 char request[kBufferMaxLength]; | 45 char request[kBufferMaxLength]; |
47 memcpy(request + kLengthOfLength, kAddressPrefix, arraysize(kAddressPrefix)); | 46 memcpy(request + kLengthOfLength, kAddressPrefix, arraysize(kAddressPrefix)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 LOG(ERROR) << "Bad response from ADB: length: " << response_length | 97 LOG(ERROR) << "Bad response from ADB: length: " << response_length |
99 << " data: " << DumpBinary(response, response_length); | 98 << " data: " << DumpBinary(response, response_length); |
100 CloseSocket(host_socket); | 99 CloseSocket(host_socket); |
101 return -1; | 100 return -1; |
102 } | 101 } |
103 | 102 |
104 return host_socket; | 103 return host_socket; |
105 } | 104 } |
106 | 105 |
107 } // namespace tools | 106 } // namespace tools |
OLD | NEW |