* Add new options to (1) force a rescan at startup, (2) display help text, and (3) bind to a specified network interface.

This commit is contained in:
Justin Maggard 2009-06-30 02:05:32 +00:00
parent efc2ab6b2b
commit d1049476ef
4 changed files with 76 additions and 18 deletions

View File

@ -253,6 +253,15 @@ init(int argc, char * * argv)
{
switch(ary_options[i].id)
{
case UPNPIFNAME:
if(getifaddr(ary_options[i].value, ext_ip_addr, INET_ADDRSTRLEN) >= 0)
{
if( *ext_ip_addr && parselanaddr(&lan_addr[n_lan_addr], ext_ip_addr) == 0 )
n_lan_addr++;
}
else
fprintf(stderr, "Interface %s not found, ignoring.\n", ary_options[i].value);
break;
case UPNPLISTENING_IP:
if(n_lan_addr < MAX_LAN_ADDR)
{
@ -374,6 +383,11 @@ init(int argc, char * * argv)
{
fprintf(stderr, "Unknown option: %s\n", argv[i]);
}
else if(strcmp(argv[i], "--help")==0)
{
runtime_vars.port = 0;
break;
}
else switch(argv[i][1])
{
case 't':
@ -449,9 +463,50 @@ init(int argc, char * * argv)
else
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
break;
case 'i':
if(i+1 < argc)
{
int address_already_there = 0;
int j;
i++;
if( getifaddr(argv[i], ext_ip_addr, INET_ADDRSTRLEN) < 0 )
{
fprintf(stderr, "Network interface '%s' not found.\n",
argv[i]);
exit(-1);
}
for(j=0; j<n_lan_addr; j++)
{
struct lan_addr_s tmpaddr;
parselanaddr(&tmpaddr, ext_ip_addr);
if(0 == strcmp(lan_addr[j].str, tmpaddr.str))
address_already_there = 1;
}
if(address_already_there)
break;
if(n_lan_addr < MAX_LAN_ADDR)
{
if(parselanaddr(&lan_addr[n_lan_addr], ext_ip_addr) == 0)
n_lan_addr++;
}
else
{
fprintf(stderr, "Too many listening ips (max: %d), ignoring %s\n",
MAX_LAN_ADDR, argv[i]);
}
}
else
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
break;
case 'f':
i++; /* discarding, the config file is already read */
break;
case 'h':
runtime_vars.port = 0; // triggers help display
break;
case 'R':
system("rm -rf " DB_PATH); // triggers a full rescan
break;
case 'V':
printf("Version " MINIDLNA_VERSION "\n");
exit(0);
@ -478,18 +533,20 @@ init(int argc, char * * argv)
if( (n_lan_addr==0) || (runtime_vars.port<=0) )
{
fprintf(stderr, "Usage:\n\t"
"%s [-f config_file]\n"
"\t\t[-a listening_ip] [-p port] [-d]\n"
/*"[-l logfile] " not functionnal */
"\t\t[-s serial] [-m model_number] \n"
"\t\t[-t notify_interval] [-P pid_filename]\n"
"\t\t[-w url]\n"
"%s [-d] [-f config_file]\n"
"\t\t[-a listening_ip] [-p port]\n"
/*"[-l logfile] " not functionnal */
"\t\t[-s serial] [-m model_number] \n"
"\t\t[-t notify_interval] [-P pid_filename]\n"
"\t\t[-w url] [-R] [-V] [-h]\n"
"\nNotes:\n\tNotify interval is in seconds. Default is 895 seconds.\n"
"\tDefault pid file is %s.\n"
"\tWith -d minidlna will run in debug mode (not daemonize).\n"
"\t-w sets the presentation url. Default is http address on port 80\n"
"\t-V print the version number\n"
"", argv[0], pidfilename);
"\tDefault pid file is %s.\n"
"\tWith -d minidlna will run in debug mode (not daemonize).\n"
"\t-w sets the presentation url. Default is http address on port 80\n"
"\t-h displays this text\n"
"\t-R forces a full rescan\n"
"\t-V print the version number\n",
argv[0], pidfilename);
return 1;
}

View File

@ -1,6 +1,9 @@
# port for HTTP (descriptions and SOAP) traffic
# port for HTTP (descriptions, SOAP, media transfer) traffic
port=8200
# network interface to bind to (this is the only interface that will serve files)
#network_interface=eth0
# set this to the directory you want scanned.
# * if have multiple directories, you can have multiple media_dir= lines
# * if you want to restrict a media_dir to a specific content type, you

View File

@ -20,8 +20,7 @@ static const struct {
enum upnpconfigoptions id;
const char * name;
} optionids[] = {
{ UPNPEXT_IFNAME, "ext_ifname" },
{ UPNPEXT_IP, "ext_ip" },
{ UPNPIFNAME, "network_interface" },
{ UPNPLISTENING_IP, "listening_ip" },
{ UPNPPORT, "port" },
{ UPNPPRESENTATIONURL, "presentation_url" },

View File

@ -13,13 +13,12 @@
/* enum of option available in the miniupnpd.conf */
enum upnpconfigoptions {
UPNP_INVALID = 0,
UPNPEXT_IFNAME = 1, /* ext_ifname */
UPNPEXT_IP, /* ext_ip */
UPNPIFNAME = 1, /* ext_ifname */
UPNPLISTENING_IP, /* listening_ip */
UPNPPORT, /* "port" */
UPNPPORT, /* port */
UPNPPRESENTATIONURL, /* presentation_url */
UPNPNOTIFY_INTERVAL, /* notify_interval */
UPNPSYSTEM_UPTIME, /* "system_uptime" */
UPNPSYSTEM_UPTIME, /* system_uptime */
UPNPUUID, /* uuid */
UPNPSERIAL, /* serial */
UPNPMODEL_NUMBER, /* model_number */