summaryrefslogtreecommitdiffstats
path: root/adb/adb.c
diff options
context:
space:
mode:
Diffstat (limited to 'adb/adb.c')
-rw-r--r--adb/adb.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/adb/adb.c b/adb/adb.c
index 1584dbe..04785fd 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -687,7 +687,7 @@ void start_device_log(void)
#endif
#if ADB_HOST
-int launch_server()
+int launch_server(int server_port)
{
#ifdef HAVE_WIN32_PROC
/* we need to start the server in the background */
@@ -822,7 +822,17 @@ int launch_server()
}
#endif
-int adb_main(int is_daemon)
+/* Constructs a local name of form tcp:port.
+ * target_str points to the target string, it's content will be overwritten.
+ * target_size is the capacity of the target string.
+ * server_port is the port number to use for the local name.
+ */
+void build_local_name(char* target_str, size_t target_size, int server_port)
+{
+ snprintf(target_str, target_size, "tcp:%d", server_port);
+}
+
+int adb_main(int is_daemon, int server_port)
{
#if !ADB_HOST
int secure = 0;
@@ -845,9 +855,11 @@ int adb_main(int is_daemon)
HOST = 1;
usb_vendors_init();
usb_init();
- local_init(ADB_LOCAL_TRANSPORT_PORT);
+ local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
- if(install_listener("tcp:5037", "*smartsocket*", NULL)) {
+ char local_name[30];
+ build_local_name(local_name, sizeof(local_name), server_port);
+ if(install_listener(local_name, "*smartsocket*", NULL)) {
exit(1);
}
#else
@@ -873,7 +885,7 @@ int adb_main(int is_daemon)
}
}
- /* don't listen on port 5037 if we are running in secure mode */
+ /* don't listen on a port (default 5037) if running in secure mode */
/* don't run as root if we are running in secure mode */
if (secure) {
struct __user_cap_header_struct header;
@@ -906,9 +918,11 @@ int adb_main(int is_daemon)
cap.inheritable = 0;
capset(&header, &cap);
- D("Local port 5037 disabled\n");
+ D("Local port disabled\n");
} else {
- if(install_listener("tcp:5037", "*smartsocket*", NULL)) {
+ char local_name[30];
+ build_local_name(local_name, sizeof(local_name), server_port);
+ if(install_listener(local_name, "*smartsocket*", NULL)) {
exit(1);
}
}
@@ -929,7 +943,7 @@ int adb_main(int is_daemon)
usb_init();
} else {
// listen on default port
- local_init(ADB_LOCAL_TRANSPORT_PORT);
+ local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
}
init_jdwp();
#endif
@@ -1170,6 +1184,6 @@ int main(int argc, char **argv)
}
start_device_log();
- return adb_main(0);
+ return adb_main(0, DEFAULT_ADB_PORT);
#endif
}