[PATCH v2 2/4] staging: usbip: set usbipd server port via "-t" / "--tcp-port" option.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add an option "-t" / "--tcp-port" to specify the TCP port to listen on.

Signed-off-by: Anthony Foiani <anthony.foiani@xxxxxxxxx>
---
 drivers/staging/usbip/userspace/src/usbip.c        |  9 +++++--
 .../staging/usbip/userspace/src/usbip_network.c    | 30 ++++++++++++++++++++++
 .../staging/usbip/userspace/src/usbip_network.h    |  5 ++--
 drivers/staging/usbip/userspace/src/usbipd.c       |  9 ++++++-
 4 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip.c b/drivers/staging/usbip/userspace/src/usbip.c
index fff4b76..69ac4b5 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -26,6 +26,7 @@
 #include <syslog.h>
 
 #include "usbip_common.h"
+#include "usbip_network.h"
 #include "usbip.h"
 
 static int usbip_help(int argc, char *argv[]);
@@ -34,7 +35,7 @@ static int usbip_version(int argc, char *argv[]);
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbip_usage_string[] =
-	"usbip [--debug] [--log] [version]\n"
+	"usbip [--debug] [--log] [--tcp-port PORT] [version]\n"
 	"             [help] <command> <args>\n";
 
 static void usbip_usage(void)
@@ -140,6 +141,7 @@ int main(int argc, char *argv[])
 	static const struct option opts[] = {
 		{ "debug", no_argument, NULL, 'd' },
 		{ "log",   no_argument, NULL, 'l' },
+		{ "tcp-port",  required_argument, NULL, 't' },
 		{ NULL,    0,           NULL,  0  }
 	};
 
@@ -150,7 +152,7 @@ int main(int argc, char *argv[])
 	usbip_use_stderr = 1;
 	opterr = 0;
 	for (;;) {
-		opt = getopt_long(argc, argv, "+d", opts, NULL);
+		opt = getopt_long(argc, argv, "+dt:", opts, NULL);
 
 		if (opt == -1)
 			break;
@@ -163,6 +165,9 @@ int main(int argc, char *argv[])
 			usbip_use_syslog = 1;
 			openlog("", LOG_PID, LOG_USER);
 			break;
+		case 't':
+			usbip_setup_port_number(optarg);
+			break;
 		case '?':
 			printf("usbip: invalid option\n");
 		default:
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c b/drivers/staging/usbip/userspace/src/usbip_network.c
index b12448e..3e8eed4 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -28,6 +28,36 @@
 #include "usbip_common.h"
 #include "usbip_network.h"
 
+int USBIP_PORT = 3240;
+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;
+	}
+
+	if (*end != '\0') {
+		err("port: garbage at end of '%s'", arg);
+		return;
+	}
+
+	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);
+}
+
 void usbip_net_pack_uint32_t(int pack, uint32_t *num)
 {
 	uint32_t i;
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.h b/drivers/staging/usbip/userspace/src/usbip_network.h
index 1bbefc9..203858c 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.h
+++ b/drivers/staging/usbip/userspace/src/usbip_network.h
@@ -14,8 +14,9 @@
 
 #include <stdint.h>
 
-#define USBIP_PORT 3240
-#define USBIP_PORT_STRING "3240"
+extern int USBIP_PORT;
+extern char *USBIP_PORT_STRING;
+void usbip_setup_port_number(char *arg);
 
 /* ---------------------------------------------------------------------- */
 /* Common header for all the kinds of PDUs. */
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c b/drivers/staging/usbip/userspace/src/usbipd.c
index f31b8b4..c0bb689 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -66,6 +66,9 @@ static const char usbipd_help_string[] =
 	"		Write process id to FILE.\n"
 	"		If no FILE specified, use " DEFAULT_PID_FILE "\n"
 	"\n"
+	"	-tPORT, --tcp-port PORT\n"
+	"		Listen on TCP/IP port PORT.\n"
+	"\n"
 	"	-h, --help\n"
 	"		Print this help.\n"
 	"\n"
@@ -560,6 +563,7 @@ int main(int argc, char *argv[])
 		{ "daemon",  no_argument, NULL, 'D' },
 		{ "debug",   no_argument, NULL, 'd' },
 		{ "pid",     optional_argument, NULL, 'P' },
+		{ "tcp-port", required_argument, NULL, 't' },
 		{ "help",    no_argument, NULL, 'h' },
 		{ "version", no_argument, NULL, 'v' },
 		{ NULL,	     0,           NULL,  0  }
@@ -583,7 +587,7 @@ int main(int argc, char *argv[])
 
 	cmd = cmd_standalone_mode;
 	for (;;) {
-		opt = getopt_long(argc, argv, "DdP::hv", longopts, NULL);
+		opt = getopt_long(argc, argv, "DdP::t:hv", longopts, NULL);
 
 		if (opt == -1)
 			break;
@@ -601,6 +605,9 @@ int main(int argc, char *argv[])
 		case 'P':
 			pid_file = optarg ? optarg : DEFAULT_PID_FILE;
 			break;
+		case 't':
+			usbip_setup_port_number(optarg);
+			break;
 		case 'v':
 			cmd = cmd_version;
 			break;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux