Skip to content

Commit

Permalink
Allow to bind to a dedicated interface when supported by libupnp
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Heimpold <[email protected]>
  • Loading branch information
mhei committed Sep 30, 2015
1 parent 20b07db commit f5fbe43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}

#ifdef UPNP_ENABLE_IPV6
rv = UpnpInit2(options->interface, 0);
#else
if (options->interface)
fprintf(stderr, "Warning: ignoring interface argument, not supported by libupnp.\n");
rv = UpnpInit(NULL, 0);
#endif
if (rv != UPNP_E_SUCCESS) {
fprintf(stderr, "UpnpInit failed: %d\n", rv);
return EXIT_FAILURE;
Expand Down
7 changes: 4 additions & 3 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#define SYSLOG_NAMES
#include <syslog.h>
#include <getopt.h>

#include "options.h"
Expand Down Expand Up @@ -44,6 +42,7 @@ const struct option long_options[] = {
{ "serialNumber", required_argument, 0, 'S' },
{ "uuid", required_argument, 0, 'u' },
{ "httpsURL", no_argument, 0, 's' },
{ "interface", required_argument, 0, 'i' },

{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
Expand All @@ -62,6 +61,7 @@ const char *long_options_descs[] = {
"manufacturer's serial number",
"UUID of this device",
"generate a HTTPS URL for the presentation URL (HTTP is used by default)",
"network interface to use",

"print version and exit",
"print this usage and exit",
Expand Down Expand Up @@ -95,7 +95,7 @@ int options_parse_cli(int argc, char *argv[], config_options_t *options)
int rc = EXIT_FAILURE;

while (1) {
int c = getopt_long(argc, argv, "f:M:m:D:P:N:p:S:u:sVh", long_options, NULL);
int c = getopt_long(argc, argv, "f:M:m:D:P:N:p:S:u:si:Vh", long_options, NULL);

/* detect the end of the options */
if (c == -1) break;
Expand All @@ -111,6 +111,7 @@ int options_parse_cli(int argc, char *argv[], config_options_t *options)
case 'S': options->serialNumber = optarg; break;
case 'u': options->uuid = optarg; break;
case 's': options->use_https = 1; break;
case 'i': options->interface = optarg; break;

case 'V':
printf("%s (%s)\n", argv[0], PACKAGE_STRING);
Expand Down
1 change: 1 addition & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef struct {
char *serialNumber;
char *uuid;
char *presentationURL;
char *interface;
int use_https;
} config_options_t;

Expand Down

0 comments on commit f5fbe43

Please sign in to comment.