miniupnpd: Bind to device
This is needed when you have two interfaces with the same IP address (for example using tinc)
This commit is contained in:
parent
d31a7a23c3
commit
138ec9e972
|
@ -50,14 +50,19 @@
|
|||
static int
|
||||
AddMulticastMembership(int s, in_addr_t ifaddr)
|
||||
{
|
||||
struct ip_mreq imr; /* Ip multicast membership */
|
||||
struct ip_mreqn imr; /* Ip multicast membership */
|
||||
|
||||
/* setting up imr structure */
|
||||
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
|
||||
/*imr.imr_interface.s_addr = htonl(INADDR_ANY);*/
|
||||
imr.imr_interface.s_addr = ifaddr; /*inet_addr(ifaddr);*/
|
||||
imr.imr_address.s_addr = ifaddr; /*inet_addr(ifaddr);*/
|
||||
#ifndef MULTIPLE_EXTERNAL_IP
|
||||
imr.imr_ifindex = if_nametoindex(int_if_name);
|
||||
#else
|
||||
imr.imr_ifindex = 0;
|
||||
#endif
|
||||
|
||||
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(struct ip_mreq)) < 0)
|
||||
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(struct ip_mreqn)) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "setsockopt(udp, IP_ADD_MEMBERSHIP): %m");
|
||||
return -1;
|
||||
|
@ -155,6 +160,13 @@ OpenAndConfSSDPReceiveSocket(int ipv6)
|
|||
"OpenAndConfSSDPReceiveSocket");
|
||||
}
|
||||
|
||||
#ifndef MULTIPLE_EXTERNAL_IP
|
||||
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
|
||||
{
|
||||
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
|
||||
}
|
||||
#endif
|
||||
|
||||
if(bind(s, (struct sockaddr *)&sockname, sockname_len) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "%s: bind(udp%s): %m",
|
||||
|
|
|
@ -370,6 +370,13 @@ OpenAndConfHTTPSocket(unsigned short * port)
|
|||
listenname_len = sizeof(struct sockaddr_in);
|
||||
#endif
|
||||
|
||||
#ifndef MULTIPLE_EXTERNAL_IP
|
||||
if(setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, int_if_name, strlen(int_if_name)) < 0)
|
||||
{
|
||||
syslog(LOG_WARNING, "setsockopt(udp, SO_BINDTODEVICE): %m");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
if(bind(s,
|
||||
ipv6 ? (struct sockaddr *)&listenname6 : (struct sockaddr *)&listenname4,
|
||||
|
@ -1101,6 +1108,9 @@ init(int argc, char * * argv, struct runtime_vars * v)
|
|||
use_ext_ip_addr = ary_options[i].value;
|
||||
break;
|
||||
case UPNPLISTENING_IP:
|
||||
#ifndef MULTIPLE_EXTERNAL_IP
|
||||
int_if_name = ary_options[i].value;
|
||||
#endif
|
||||
lan_addr = (struct lan_addr_s *) malloc(sizeof(struct lan_addr_s));
|
||||
if (lan_addr == NULL)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
|
||||
/* network interface for internet */
|
||||
const char * ext_if_name = 0;
|
||||
#ifndef MULTIPLE_EXTERNAL_IP
|
||||
/* network interface for LAN */
|
||||
const char * int_if_name = 0;
|
||||
#endif
|
||||
|
||||
/* file to store leases */
|
||||
#ifdef ENABLE_LEASEFILE
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
|
||||
/* name of the network interface used to acces internet */
|
||||
extern const char * ext_if_name;
|
||||
#ifndef MULTIPLE_EXTERNAL_IP
|
||||
/* network interface for LAN */
|
||||
extern const char * int_if_name;
|
||||
#endif
|
||||
|
||||
/* file to store all leases */
|
||||
#ifdef ENABLE_LEASEFILE
|
||||
|
|
Loading…
Reference in New Issue