Allow the adb server to bind on ::1
Currently the adb server can only bind on 127.0.0.1 or * if -a is
provided. This diff adds the ability for adb to bind on ::1 as
well for use cases where you might want to force adb to be IPv6
only.
To bind the adb server on ::1
```
$ ./adb -L tcp:[::1]:1234 server
$ lsof -nPi :1234
COMMAND ... NODE NAME
adb ... TCP [::1]:1234 (LISTEN)
```
The original behaviour is also retained, so this would only affect
users explicitly specifying ::1 in the socket spec
```
$ export ANDROID_ADB_SERVER_PORT=1234
$ ./adb server
$ lsof -nPi :1234
COMMAND ... NODE NAME
adb ... TCP 127.0.0.1:1234 (LISTEN)
```
Note: I've only implemented this behaviour for posix base systems,
due to my limited understanding of networking on windows. If
needed I can do some research to implement it there as well, but
there is currently no IPv6 support at all on the windows side.
Test: New unit test and the commands in the summary
Change-Id: I23e4531e8dfda4de9348124ad7491d728aecdbf7
diff --git a/socket_spec.cpp b/socket_spec.cpp
index 98468b5..27e8c46 100644
--- a/socket_spec.cpp
+++ b/socket_spec.cpp
@@ -272,7 +272,9 @@
if (hostname.empty() && gListenAll) {
result = network_inaddr_any_server(port, SOCK_STREAM, error);
} else if (tcp_host_is_local(hostname)) {
- result = network_loopback_server(port, SOCK_STREAM, error);
+ result = network_loopback_server(port, SOCK_STREAM, error, true);
+ } else if (hostname == "::1") {
+ result = network_loopback_server(port, SOCK_STREAM, error, false);
} else {
// TODO: Implement me.
*error = "listening on specified hostname currently unsupported";