Merge "Restore default port for adb connect
."
This commit is contained in:
commit
690c8c8f25
3 changed files with 44 additions and 12 deletions
|
@ -96,9 +96,8 @@ static void help() {
|
|||
" version show version num\n"
|
||||
"\n"
|
||||
"networking:\n"
|
||||
" connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]\n"
|
||||
" disconnect [HOST[:PORT]]\n"
|
||||
" disconnect from given TCP/IP device [default port=5555], or all\n"
|
||||
" connect HOST[:PORT] connect to a device via TCP/IP\n"
|
||||
" disconnect [[HOST]:PORT] disconnect from given TCP/IP device, or all\n"
|
||||
" forward --list list all forward socket connections\n"
|
||||
" forward [--no-rebind] LOCAL REMOTE\n"
|
||||
" forward socket connection using:\n"
|
||||
|
@ -1615,13 +1614,13 @@ int adb_commandline(int argc, const char** argv) {
|
|||
return adb_query_command(query);
|
||||
}
|
||||
else if (!strcmp(argv[0], "connect")) {
|
||||
if (argc != 2) error_exit("usage: adb connect <host>[:<port>]");
|
||||
if (argc != 2) error_exit("usage: adb connect HOST[:PORT>]");
|
||||
|
||||
std::string query = android::base::StringPrintf("host:connect:%s", argv[1]);
|
||||
return adb_query_command(query);
|
||||
}
|
||||
else if (!strcmp(argv[0], "disconnect")) {
|
||||
if (argc > 2) error_exit("usage: adb disconnect [<host>[:<port>]]");
|
||||
if (argc > 2) error_exit("usage: adb disconnect [HOST[:PORT]]");
|
||||
|
||||
std::string query = android::base::StringPrintf("host:disconnect:%s",
|
||||
(argc == 2) ? argv[1] : "");
|
||||
|
|
|
@ -93,7 +93,7 @@ bool parse_tcp_socket_spec(std::string_view spec, std::string* hostname, int* po
|
|||
}
|
||||
} else {
|
||||
std::string addr(spec.substr(4));
|
||||
port_value = -1;
|
||||
port_value = DEFAULT_ADB_LOCAL_TRANSPORT_PORT;
|
||||
|
||||
// FIXME: ParseNetAddress rejects port 0. This currently doesn't hurt, because listening
|
||||
// on an address that isn't 'localhost' is unsupported.
|
||||
|
|
|
@ -20,38 +20,71 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(socket_spec, parse_tcp_socket_spec) {
|
||||
TEST(socket_spec, parse_tcp_socket_spec_just_port) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_TRUE(parse_tcp_socket_spec("tcp:5037", &hostname, &port, &serial, &error));
|
||||
EXPECT_EQ("", hostname);
|
||||
EXPECT_EQ(5037, port);
|
||||
EXPECT_EQ("", serial);
|
||||
}
|
||||
|
||||
// Bad ports:
|
||||
TEST(socket_spec, parse_tcp_socket_spec_bad_ports) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:-1", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:65536", &hostname, &port, &serial, &error));
|
||||
}
|
||||
|
||||
TEST(socket_spec, parse_tcp_socket_spec_host_and_port) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_TRUE(parse_tcp_socket_spec("tcp:localhost:1234", &hostname, &port, &serial, &error));
|
||||
EXPECT_EQ("localhost", hostname);
|
||||
EXPECT_EQ(1234, port);
|
||||
EXPECT_EQ("localhost:1234", serial);
|
||||
}
|
||||
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost", &hostname, &port, &serial, &error));
|
||||
TEST(socket_spec, parse_tcp_socket_spec_host_no_port) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_TRUE(parse_tcp_socket_spec("tcp:localhost", &hostname, &port, &serial, &error));
|
||||
EXPECT_EQ("localhost", hostname);
|
||||
EXPECT_EQ(5555, port);
|
||||
EXPECT_EQ("localhost:5555", serial);
|
||||
}
|
||||
|
||||
TEST(socket_spec, parse_tcp_socket_spec_host_bad_ports) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost:", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost:-1", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost:65536", &hostname, &port, &serial, &error));
|
||||
}
|
||||
|
||||
// IPv6:
|
||||
TEST(socket_spec, parse_tcp_socket_spec_ipv6_and_port) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_TRUE(parse_tcp_socket_spec("tcp:[::1]:1234", &hostname, &port, &serial, &error));
|
||||
EXPECT_EQ("::1", hostname);
|
||||
EXPECT_EQ(1234, port);
|
||||
EXPECT_EQ("[::1]:1234", serial);
|
||||
}
|
||||
|
||||
TEST(socket_spec, parse_tcp_socket_spec_ipv6_no_port) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_TRUE(parse_tcp_socket_spec("tcp:::1", &hostname, &port, &serial, &error));
|
||||
EXPECT_EQ("::1", hostname);
|
||||
EXPECT_EQ(5555, port);
|
||||
EXPECT_EQ("[::1]:5555", serial);
|
||||
}
|
||||
|
||||
TEST(socket_spec, parse_tcp_socket_spec_ipv6_bad_ports) {
|
||||
std::string hostname, error, serial;
|
||||
int port;
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:[::1]", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:[::1]:", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:[::1]:-1", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:::1", &hostname, &port, &serial, &error));
|
||||
EXPECT_FALSE(parse_tcp_socket_spec("tcp:::1:1234", &hostname, &port, &serial, &error));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue