staging: usbip: set usbipd server port via "-t" / "--tcp-port" option.
authorAnthony Foiani <anthony.foiani@gmail.com>
Fri, 23 Aug 2013 04:06:40 +0000 (22:06 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Aug 2013 16:54:26 +0000 (09:54 -0700)
Add an option "-t" / "--tcp-port" to specify the TCP port to listen
on.  Downcase associated variables as they're no longer constants.

Signed-off-by: Anthony Foiani <anthony.foiani@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/usbip/userspace/src/usbip.c
drivers/staging/usbip/userspace/src/usbip_attach.c
drivers/staging/usbip/userspace/src/usbip_list.c
drivers/staging/usbip/userspace/src/usbip_network.c
drivers/staging/usbip/userspace/src/usbip_network.h
drivers/staging/usbip/userspace/src/usbipd.c

index fff4b768e7052bb4388dfb5dbfa83bf8e9db635d..69ac4b569c3600c35812bfeccb059811c5dfbb64 100644 (file)
@@ -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:
index 99a24747af0c9d02dd70c5fb5002c60c7e6a1dd1..085841196522bd168c5b30c01b1e70b7ad7ea117 100644 (file)
@@ -175,7 +175,7 @@ static int attach_device(char *host, char *busid)
        int rc;
        int rhport;
 
-       sockfd = usbip_net_tcp_connect(host, USBIP_PORT_STRING);
+       sockfd = usbip_net_tcp_connect(host, usbip_port_string);
        if (sockfd < 0) {
                err("tcp connect");
                return -1;
@@ -189,7 +189,7 @@ static int attach_device(char *host, char *busid)
 
        close(sockfd);
 
-       rc = record_connection(host, USBIP_PORT_STRING, busid, rhport);
+       rc = record_connection(host, usbip_port_string, busid, rhport);
        if (rc < 0) {
                err("record connection");
                return -1;
index ff56255f497a2bac813cdcdd22417f9f44845cd0..237e099337a1f6a14c700edf26ba8c599059246f 100644 (file)
@@ -131,13 +131,13 @@ static int list_exported_devices(char *host)
        int rc;
        int sockfd;
 
-       sockfd = usbip_net_tcp_connect(host, USBIP_PORT_STRING);
+       sockfd = usbip_net_tcp_connect(host, usbip_port_string);
        if (sockfd < 0) {
                err("could not connect to %s:%s: %s", host,
-                   USBIP_PORT_STRING, gai_strerror(sockfd));
+                   usbip_port_string, gai_strerror(sockfd));
                return -1;
        }
-       dbg("connected to %s:%s", host, USBIP_PORT_STRING);
+       dbg("connected to %s:%s", host, usbip_port_string);
 
        rc = get_exported_devices(host, sockfd);
        if (rc < 0) {
index b12448ec69ab48c04e45c87a43a0b5a2f2fab746..c39a07f1d38cd0b122bebf572313d46c79d75cac 100644 (file)
 #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;
index 1bbefc993fb1f4bd9926990b554510cbc1fa0037..2d0e4277b62be808fa9dc9d87d6339e223e58ea7 100644 (file)
@@ -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. */
index f31b8b4246a36f5423629cdef0cd8afe60e8872f..f41ba5beb404377627a5b45fb49469876b1f9900 100644 (file)
@@ -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"
@@ -417,9 +420,9 @@ static struct addrinfo *do_getaddrinfo(char *host, int ai_family)
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_flags    = AI_PASSIVE;
 
-       rc = getaddrinfo(host, USBIP_PORT_STRING, &hints, &ai_head);
+       rc = getaddrinfo(host, usbip_port_string, &hints, &ai_head);
        if (rc) {
-               err("failed to get a network address %s: %s", USBIP_PORT_STRING,
+               err("failed to get a network address %s: %s", usbip_port_string,
                    gai_strerror(rc));
                return NULL;
        }
@@ -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;
This page took 0.028876 seconds and 5 git commands to generate.