At 2017-11-17 19:23:30, "Frediano Ziglio" <fziglio@xxxxxxxxxx> wrote: >> >> From: Chen Hanxiao <chenhanxiao@xxxxxxxxx> >> >> We bind our listen address to in6addr_any, which may be >> unsecure with multi network cards that belong to >> internal or external networks. >> >> This patch introduces option -4 and -6 to bind a specific >> address. >> >> Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxx> >> --- >> v2: >> replace strerror with perror >> fix some copy-paste errors >> >> usbredirserver/usbredirserver.1 | 3 +- >> usbredirserver/usbredirserver.c | 63 >> ++++++++++++++++++++++++++++++++++------- >> 2 files changed, 54 insertions(+), 12 deletions(-) >> >> diff --git a/usbredirserver/usbredirserver.1 >> b/usbredirserver/usbredirserver.1 >> index e857190..8bbce07 100644 >> --- a/usbredirserver/usbredirserver.1 >> +++ b/usbredirserver/usbredirserver.1 >> @@ -3,7 +3,8 @@ >> usbredirserver \- exporting an USB device for use from another (virtual) >> machine >> .SH SYNOPSIS >> .B usbredirserver >> -[\fI-p|--port <port>\fR] [\fI-v|--verbose <0-5>\fR] >> \fI<busnum-devnum|vendorid:prodid>\fR >> +[\fI-p|--port <port>\fR] [\fI-v|--verbose <0-5>\fR] [\fI-4 <ipv4_addr|I-6 >> <ipv6_addr>] >> +\fI<busnum-devnum|vendorid:prodid>\fR >> .SH DESCRIPTION >> usbredirserver is a small standalone server for exporting an USB device for >> use from another (virtual) machine through the usbredir protocol. >> diff --git a/usbredirserver/usbredirserver.c >> b/usbredirserver/usbredirserver.c >> index 13965dc..e2841b2 100644 >> --- a/usbredirserver/usbredirserver.c >> +++ b/usbredirserver/usbredirserver.c >> @@ -36,6 +36,7 @@ >> #include <sys/time.h> >> #include <netdb.h> >> #include <netinet/in.h> >> +#include <arpa/inet.h> >> #include "usbredirhost.h" >> >> >> @@ -49,6 +50,8 @@ static struct usbredirhost *host; >> static const struct option longopts[] = { >> { "port", required_argument, NULL, 'p' }, >> { "verbose", required_argument, NULL, 'v' }, >> + { "ipv4", required_argument, NULL, '4' }, >> + { "ipv6", required_argument, NULL, '6' }, >> { "help", no_argument, NULL, 'h' }, >> { NULL, 0, NULL, 0 } >> }; >> @@ -93,7 +96,9 @@ static int usbredirserver_write(void *priv, uint8_t *data, >> int count) >> static void usage(int exit_code, char *argv0) >> { >> fprintf(exit_code? stderr:stdout, >> - "Usage: %s [-p|--port <port>] [-v|--verbose <0-5>] >> <busnum-devnum|vendorid:prodid>\n", >> + "Usage: %s [-p|--port <port>] [-v|--verbose <0-5>] " >> + "[[-4|--ipv4 ipaddr]|[-6|--ipv6 ipaddr]] " >> + "<busnum-devnum|vendorid:prodid>\n", >> argv0); >> exit(exit_code); >> } >> @@ -198,11 +203,13 @@ int main(int argc, char *argv[]) >> int usbvendor = -1; >> int usbproduct = -1; >> int on = 1; >> + char *ipv4_addr = NULL, *ipv6_addr = NULL; >> + struct sockaddr_in serveraddr4; >> struct sockaddr_in6 serveraddr; > >Would not be better to have a sort of > >union { > struct sockaddr_in v4; > struct sockaddr_in6 v6; >} serveraddr; > >Here? This would allow some code to be reused (like memset and bind part). > Nice catch. I'll update in v3. Thanks for your advice. Regards, - Chen _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel