diff mbox series

[3/3,3/3] usbipd: use usbip_to_int to simplify usbip_setup_port_number implementation

Message ID 20250516075204.7950-3-vadimgrn@gmail.com
State New
Headers show
Series [1/3,1/3] usbipd: enable SO_KEEPALIVE socket option for accepted connection | expand

Commit Message

Vadym Hrynchyshyn May 16, 2025, 7:52 a.m. UTC
- usbip_to_int function is used for handling arguments
      of options --tcp-keepidle,--tcp-keepcnt,--tcp-keepintvl.
      It is now called from usbip_setup_port_number to handle
      tcp port number. This simplifies its implementation.

Signed-off-by: Vadym Hrynchyshyn <vadimgrn@gmail.com>
---
 tools/usb/usbip/src/usbip_network.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/tools/usb/usbip/src/usbip_network.c b/tools/usb/usbip/src/usbip_network.c
index 15787044a7c9..26559a11e648 100644
--- a/tools/usb/usbip/src/usbip_network.c
+++ b/tools/usb/usbip/src/usbip_network.c
@@ -26,28 +26,13 @@  char *usbip_port_string = "3240";
 void usbip_setup_port_number(char *arg)
 {
 	dbg("parsing port arg '%s'", arg);
-	char *end;
-	unsigned long int port = strtoul(arg, &end, 10);
-
-	if (end == arg) {
-		err("port: could not parse '%s' as a decimal integer", arg);
-		return;
-	}
+	int port = usbip_to_int("port", arg, UINT16_MAX);
 
-	if (*end != '\0') {
-		err("port: garbage at end of '%s'", arg);
-		return;
+	if (port > 0) {
+		usbip_port = port;
+		usbip_port_string = arg;
+		info("using port %d (\"%s\")", usbip_port, usbip_port_string);
 	}
-
-	if (port > UINT16_MAX) {
-		err("port: %s too high (max=%d)",
-		    arg, UINT16_MAX);
-		return;
-	}
-
-	usbip_port = port;
-	usbip_port_string = arg;
-	info("using port %d (\"%s\")", usbip_port, usbip_port_string);
 }
 
 int usbip_to_int(const char *name, const char *val, int maxval)