Allow LAN interface to be given as interface names.

(instead of interface IP addresses)
It will allow IPv6 operations.
This commit is contained in:
Thomas Bernard 2012-04-06 17:31:24 +02:00
parent 225b59a6d3
commit 6d32d69608
4 changed files with 44 additions and 11 deletions

View File

@ -1,6 +1,8 @@
$Id: Changelog.txt,v 1.266 2012/04/06 15:27:20 nanard Exp $
2012/04/06:
Allow LAN interface to be given as interface names, instead of interface
IP addresses. It will allow IPv6 operations.
fix linux/getifstats.c when bitrate is unknown
2012/03/31:

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpd.c,v 1.149 2012/03/31 06:57:12 nanard Exp $ */
/* $Id: miniupnpd.c,v 1.150 2012/04/06 15:27:20 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -519,6 +519,8 @@ struct runtime_vars {
* external interface associated with the lan subnet follows.
* ex : 192.168.1.1/24 81.21.41.11
*
* Can also use the interface name (ie eth0)
*
* return value :
* 0 : ok
* -1 : error */
@ -529,14 +531,26 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
int n;
char tmp[16];
memset(lan_addr, 0, sizeof(struct lan_addr_s));
p = str;
while(*p && *p != '/' && !isspace(*p))
p++;
n = p - str;
if(n>15)
goto parselan_error;
memcpy(lan_addr->str, str, n);
lan_addr->str[n] = '\0';
if(!isdigit(str[0]) && n < sizeof(lan_addr->ifname))
{
/* not starting with a digit : suppose it is an interface name */
memcpy(lan_addr->ifname, str, n);
lan_addr->ifname[n] = '\0';
if(getifaddr(lan_addr->ifname, lan_addr->str, sizeof(lan_addr->str)) < 0)
goto parselan_error;
}
else
{
if(n>15)
goto parselan_error;
memcpy(lan_addr->str, str, n);
lan_addr->str[n] = '\0';
}
if(!inet_aton(lan_addr->str, &lan_addr->addr))
goto parselan_error;
if(*p == '/')
@ -587,10 +601,20 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
}
}
}
#endif
#ifdef ENABLE_IPV6
if(lan_addr->ifname[0] != '\0')
{
lan_addr->index = if_nametoindex(lan_addr->ifname);
if(lan_addr->index == 0)
fprintf(stderr, "Cannot get index for network interface %s",
lan_addr->ifname);
}
#endif
return 0;
parselan_error:
fprintf(stderr, "Error parsing address/mask : %s\n", str);
fprintf(stderr, "Error parsing address/mask (or interface name) : %s\n",
str);
return -1;
}

View File

@ -8,13 +8,15 @@ ext_ifname=eth1
# LAN network interfaces IPs / networks
# there can be multiple listening ips for SSDP traffic.
# should be under the form nnn.nnn.nnn.nnn/nn
# HTTP is available on all interfaces
# It can also be the network interface name (ie "eth0")
# It if mandatory to use the network interface name to enable IPv6
# HTTP is available on all interfaces.
# When MULTIPLE_EXTERNAL_IP is enabled, the external ip
# address associated with the subnet follows. for example :
# listening_ip=192.168.0.1/24 88.22.44.13
#listening_ip=192.168.0.1/24
listening_ip=192.168.11.33/24
#listening_ip=
listening_ip=192.168.10.109/24
#listening_ip=eth0
# port for HTTP (descriptions and SOAP) traffic. set 0 for autoselect.
port=0

View File

@ -1,7 +1,7 @@
/* $Id: miniupnpdtypes.h,v 1.3 2011/05/13 13:56:18 nanard Exp $ */
/* $Id: miniupnpdtypes.h,v 1.4 2012/04/06 15:27:21 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2007 Thomas Bernard
* (c) 2006-2012 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#ifndef __MINIUPNPDTYPES_H__
@ -9,11 +9,16 @@
#include "config.h"
#include <netinet/in.h>
#include <net/if.h>
#include <sys/queue.h>
/* structure and list for storing lan addresses
* with ascii representation and mask */
struct lan_addr_s {
char ifname[IFNAMSIZ]; /* example: eth0 */
#ifdef ENABLE_IPV6
unsigned int index; /* use if_nametoindex() */
#endif
char str[16]; /* example: 192.168.0.1 */
struct in_addr addr, mask; /* ip/mask */
#ifdef MULTIPLE_EXTERNAL_IP