From 02d46b226210e407d940ea95f16047985f883174 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 6 Feb 2022 15:02:29 +0100 Subject: [PATCH] Expose function to test if a serial is TCP/IP In practice, it just tests if the serial contains a ':', which is sufficient to distinguish ip:port from a real USB serial. PR #3005 --- app/src/adb/adb.c | 5 +++++ app/src/adb/adb.h | 9 +++++++++ app/src/server.c | 5 +---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/adb/adb.c b/app/src/adb/adb.c index 3cfc5a95..b00bd620 100644 --- a/app/src/adb/adb.c +++ b/app/src/adb/adb.c @@ -482,3 +482,8 @@ sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags) { return sc_adb_parse_device_ip_from_output(buf); } + +bool +sc_adb_is_serial_tcpip(const char *serial) { + return strchr(serial, ':'); +} diff --git a/app/src/adb/adb.h b/app/src/adb/adb.h index 1a97c203..18a11438 100644 --- a/app/src/adb/adb.h +++ b/app/src/adb/adb.h @@ -93,4 +93,13 @@ sc_adb_get_serialno(struct sc_intr *intr, unsigned flags); char * sc_adb_get_device_ip(struct sc_intr *intr, const char *serial, unsigned flags); +/** + * Indicate if the serial represents an IP address + * + * In practice, it just returns true if and only if it contains a ':', which is + * sufficient to distinguish an ip:port from a real USB serial. + */ +bool +sc_adb_is_serial_tcpip(const char *serial); + #endif diff --git a/app/src/server.c b/app/src/server.c index b0b596ad..3dbda0e9 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -659,10 +659,7 @@ sc_server_configure_tcpip_known_address(struct sc_server *server, static bool sc_server_configure_tcpip_unknown_address(struct sc_server *server, const char *serial) { - // The serial is either the real serial when connected via USB, or - // the IP:PORT when connected over TCP/IP. Only the latter contains - // a colon. - bool is_already_tcpip = strchr(serial, ':'); + bool is_already_tcpip = sc_adb_is_serial_tcpip(serial); if (is_already_tcpip) { // Nothing to do LOGI("Device already connected via TCP/IP: %s", serial);