miniupnpd/portinuse: port_in_use() returns -1 in case of error
This commit is contained in:
parent
aea062a7ba
commit
6419602e14
|
@ -293,8 +293,9 @@ void ProcessIncomingNATPMPPacket(int s, unsigned char *msg_buff, int len,
|
|||
}
|
||||
any_eport_allowed = 1; /* at lease one eport is allowed */
|
||||
#ifdef CHECK_PORTINUSE
|
||||
if (port_in_use(ext_if_name, eport, proto, senderaddrstr, iport)) {
|
||||
syslog(LOG_INFO, "port %hu protocol %s already in use", eport, (proto==IPPROTO_TCP)?"tcp":"udp");
|
||||
if (port_in_use(ext_if_name, eport, proto, senderaddrstr, iport) > 0) {
|
||||
syslog(LOG_INFO, "port %hu protocol %s already in use",
|
||||
eport, (proto==IPPROTO_TCP)?"tcp":"udp");
|
||||
eport++;
|
||||
if(eport == 0) eport++; /* skip port zero */
|
||||
continue;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id $ */
|
||||
/* $Id: $ */
|
||||
/* MiniUPnP project
|
||||
* (c) 2007-2014 Thomas Bernard
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
|
@ -83,13 +83,14 @@ port_in_use(const char *if_name,
|
|||
ip_addr.s_addr = 0;
|
||||
|
||||
syslog(LOG_DEBUG, "Check protocol %s for port %d on ext_if %s %s, %08X",
|
||||
(proto==IPPROTO_TCP)?"tcp":"udp", eport, if_name, ip_addr_str, (unsigned)ip_addr.s_addr);
|
||||
(proto==IPPROTO_TCP)?"tcp":"udp", eport, if_name,
|
||||
ip_addr_str, (unsigned)ip_addr.s_addr);
|
||||
|
||||
#ifdef __linux__
|
||||
f = fopen((proto==IPPROTO_TCP)?tcpfile:udpfile, "r");
|
||||
if (!f) {
|
||||
syslog(LOG_ERR, "cannot open %s", (proto==IPPROTO_TCP)?tcpfile:udpfile);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(line, 255, f)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id $ */
|
||||
/* $Id: $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2014 Thomas Bernard
|
||||
|
@ -12,7 +12,8 @@
|
|||
/* portinuse()
|
||||
* determine wether a port is already in use
|
||||
* on a given interface.
|
||||
* returns: 0 not in use, 1 in use */
|
||||
* returns: 0 not in use, > 0 in use
|
||||
* -1 in case of error */
|
||||
int
|
||||
port_in_use(const char *if_name,
|
||||
unsigned port, int proto,
|
||||
|
|
|
@ -296,8 +296,9 @@ upnp_redirect(const char * rhost, unsigned short eport,
|
|||
return -2;
|
||||
}
|
||||
#ifdef CHECK_PORTINUSE
|
||||
} else if (port_in_use(ext_if_name, eport, proto, iaddr, iport)) {
|
||||
syslog(LOG_INFO, "port %hu protocol %s already in use", eport, protocol);
|
||||
} else if (port_in_use(ext_if_name, eport, proto, iaddr, iport) > 0) {
|
||||
syslog(LOG_INFO, "port %hu protocol %s already in use",
|
||||
eport, protocol);
|
||||
return -2;
|
||||
#endif /* CHECK_PORTINUSE */
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue