Merge branch 'issue-464'
This commit is contained in:
commit
2cb3589d59
|
@ -1,4 +1,8 @@
|
||||||
$Id: Changelog.txt,v 1.50 2019/02/10 13:45:24 nanard Exp $
|
$Id: Changelog.txt,v 1.52 2020/06/06 20:20:47 nanard Exp $
|
||||||
|
|
||||||
|
2020/06/06:
|
||||||
|
define NO_BACKGROUND_NO_PIDFILE for a systemd friendly mode
|
||||||
|
send the startup M-SEARCH message on the right interface(s)
|
||||||
|
|
||||||
2018/12/18:
|
2018/12/18:
|
||||||
updateDevice() remove element from the list when realloc fails
|
updateDevice() remove element from the list when realloc fails
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
/* $Id: asyncsendto.c,v 1.10 2018/07/06 11:44:59 nanard Exp $ */
|
/* $Id: asyncsendto.c,v 1.11 2019/09/24 11:46:01 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
* (c) 2006-2018 Thomas Bernard
|
* (c) 2006-2019 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/select.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* $Id: config.h,v 1.10 2018/02/23 13:58:14 nanard Exp $ */
|
/* $Id: config.h,v 1.12 2020/06/06 20:20:47 nanard Exp $ */
|
||||||
/* MiniUPnP project
|
/* MiniUPnP project
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
||||||
* (c) 2006-2018 Thomas Bernard
|
* (c) 2006-2020 Thomas Bernard
|
||||||
* This software is subject to the conditions detailed
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
#ifndef CONFIG_H_INCLUDED
|
#ifndef CONFIG_H_INCLUDED
|
||||||
|
@ -30,4 +30,13 @@
|
||||||
* and unicasted, we cannot bind to 239.255.255.250 neither */
|
* and unicasted, we cannot bind to 239.255.255.250 neither */
|
||||||
/*#define SSDP_LISTEN_ON_SPECIFIC_ADDR*/
|
/*#define SSDP_LISTEN_ON_SPECIFIC_ADDR*/
|
||||||
|
|
||||||
|
/* When NO_BACKGROUND_NO_PIDFILE is defined, minissdpd does not go to
|
||||||
|
* background and does not create any pidfile */
|
||||||
|
/*#define NO_BACKGROUND_NO_PIDFILE*/
|
||||||
|
|
||||||
|
/* define HAVE_IP_MREQN to use struct ip_mreqn instead of struct ip_mreq
|
||||||
|
* for setsockopt(IP_MULTICAST_IF). Available with Linux 2.4+,
|
||||||
|
* FreeBSD, etc. */
|
||||||
|
#define HAVE_IP_MREQN
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* $Id: minissdpd.c,v 1.53 2016/03/01 18:06:46 nanard Exp $ */
|
/* $Id: minissdpd.c,v 1.58 2020/06/06 20:20:47 nanard Exp $ */
|
||||||
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||||
* MiniUPnP project
|
* MiniUPnP project
|
||||||
* (c) 2007-2018 Thomas Bernard
|
* (c) 2007-2020 Thomas Bernard
|
||||||
* website : http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
* website : http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
|
||||||
* This software is subject to the conditions detailed
|
* This software is subject to the conditions detailed
|
||||||
* in the LICENCE file provided within the distribution */
|
* in the LICENCE file provided within the distribution */
|
||||||
|
@ -1215,7 +1215,7 @@ static void ssdpDiscover(int s, int ipv6, const char * search)
|
||||||
n = sendto_or_schedule(s, bufr, n, 0, (const struct sockaddr *)&sockudp_w,
|
n = sendto_or_schedule(s, bufr, n, 0, (const struct sockaddr *)&sockudp_w,
|
||||||
ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in));
|
ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in));
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
syslog(LOG_ERR, "%s: sendto: %m", __func__);
|
syslog(LOG_ERR, "%s: sendto(s=%d, ipv6=%d): %m", __func__, s, ipv6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1224,7 +1224,9 @@ static void ssdpDiscover(int s, int ipv6, const char * search)
|
||||||
int main(int argc, char * * argv)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
int pid;
|
int pid;
|
||||||
|
#endif
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
char buf[1500];
|
char buf[1500];
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
@ -1245,7 +1247,9 @@ int main(int argc, char * * argv)
|
||||||
struct lan_addr_s * lan_addr;
|
struct lan_addr_s * lan_addr;
|
||||||
int i;
|
int i;
|
||||||
const char * sockpath = "/var/run/minissdpd.sock";
|
const char * sockpath = "/var/run/minissdpd.sock";
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
const char * pidfilename = "/var/run/minissdpd.pid";
|
const char * pidfilename = "/var/run/minissdpd.pid";
|
||||||
|
#endif
|
||||||
int debug_flag = 0;
|
int debug_flag = 0;
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
int ipv6 = 0;
|
int ipv6 = 0;
|
||||||
|
@ -1291,8 +1295,10 @@ int main(int argc, char * * argv)
|
||||||
}
|
}
|
||||||
} else if(0==strcmp(argv[i], "-s"))
|
} else if(0==strcmp(argv[i], "-s"))
|
||||||
sockpath = argv[++i];
|
sockpath = argv[++i];
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
else if(0==strcmp(argv[i], "-p"))
|
else if(0==strcmp(argv[i], "-p"))
|
||||||
pidfilename = argv[++i];
|
pidfilename = argv[++i];
|
||||||
|
#endif
|
||||||
else if(0==strcmp(argv[i], "-t"))
|
else if(0==strcmp(argv[i], "-t"))
|
||||||
ttl = (unsigned char)atoi(argv[++i]);
|
ttl = (unsigned char)atoi(argv[++i]);
|
||||||
else if(0==strcmp(argv[i], "-f"))
|
else if(0==strcmp(argv[i], "-f"))
|
||||||
|
@ -1308,7 +1314,11 @@ int main(int argc, char * * argv)
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
"[-6] "
|
"[-6] "
|
||||||
#endif /* ENABLE_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
"[-s socket] [-p pidfile] [-t TTL] "
|
"[-s socket] "
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
|
"[-p pidfile] "
|
||||||
|
#endif
|
||||||
|
"[-t TTL] "
|
||||||
"[-f device] "
|
"[-f device] "
|
||||||
"-i <interface> [-i <interface2>] ...\n",
|
"-i <interface> [-i <interface2>] ...\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
@ -1317,8 +1327,13 @@ int main(int argc, char * * argv)
|
||||||
" 192.168.1.42/255.255.255.0, or an interface name such as eth0.\n");
|
" 192.168.1.42/255.255.255.0, or an interface name such as eth0.\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\n By default, socket will be open as %s\n"
|
"\n By default, socket will be open as %s\n"
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
" and pid written to file %s\n",
|
" and pid written to file %s\n",
|
||||||
sockpath, pidfilename);
|
sockpath, pidfilename
|
||||||
|
#else
|
||||||
|
,sockpath
|
||||||
|
#endif
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1329,11 +1344,13 @@ int main(int argc, char * * argv)
|
||||||
if(!debug_flag) /* speed things up and ignore LOG_INFO and LOG_DEBUG */
|
if(!debug_flag) /* speed things up and ignore LOG_INFO and LOG_DEBUG */
|
||||||
setlogmask(LOG_UPTO(LOG_NOTICE));
|
setlogmask(LOG_UPTO(LOG_NOTICE));
|
||||||
|
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
if(checkforrunning(pidfilename) < 0)
|
if(checkforrunning(pidfilename) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "MiniSSDPd is already running. EXITING");
|
syslog(LOG_ERR, "MiniSSDPd is already running. EXITING");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
upnp_bootid = (unsigned int)time(NULL);
|
upnp_bootid = (unsigned int)time(NULL);
|
||||||
|
|
||||||
|
@ -1414,6 +1431,7 @@ int main(int argc, char * * argv)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
/* daemonize or in any case get pid ! */
|
/* daemonize or in any case get pid ! */
|
||||||
if(debug_flag)
|
if(debug_flag)
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
|
@ -1428,10 +1446,33 @@ int main(int argc, char * * argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
writepidfile(pidfilename, pid);
|
writepidfile(pidfilename, pid);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* send M-SEARCH ssdp:all Requests */
|
/* send M-SEARCH ssdp:all Requests */
|
||||||
if(s_ssdp >= 0)
|
if(s_ssdp >= 0) {
|
||||||
ssdpDiscover(s_ssdp, 0, searched_device);
|
for(lan_addr = lan_addrs.lh_first; lan_addr != NULL; lan_addr = lan_addr->list.le_next) {
|
||||||
|
#ifndef HAVE_IP_MREQN
|
||||||
|
struct in_addr mc_if;
|
||||||
|
|
||||||
|
mc_if.s_addr = lan_addr->addr.s_addr; /*inet_addr(addr);*/
|
||||||
|
#else
|
||||||
|
struct ip_mreqn mc_if;
|
||||||
|
|
||||||
|
mc_if.imr_address.s_addr = lan_addr->addr.s_addr; /*inet_addr(addr);*/
|
||||||
|
#ifdef ENABLE_IPV6
|
||||||
|
mc_if.imr_ifindex = lan_addr->index;
|
||||||
|
#else /* ENABLE_IPV6 */
|
||||||
|
mc_if.imr_ifindex = if_nametoindex(lan_addr->ifname);
|
||||||
|
#endif /* ENABLE_IPV6 */
|
||||||
|
#endif /* HAVE_IP_MREQN */
|
||||||
|
if(setsockopt(s_ssdp, IPPROTO_IP, IP_MULTICAST_IF, &mc_if, sizeof(mc_if)) < 0) {
|
||||||
|
syslog(LOG_WARNING, "setsockopt(IP_MULTICAST_IF): %m");
|
||||||
|
}
|
||||||
|
ssdpDiscover(s_ssdp, 0, searched_device);
|
||||||
|
/* XXX if ssdpDiscover() doesn't send the SSDP packet at once,
|
||||||
|
* we should wait here */
|
||||||
|
}
|
||||||
|
}
|
||||||
if(s_ssdp6 >= 0)
|
if(s_ssdp6 >= 0)
|
||||||
ssdpDiscover(s_ssdp6, 1, searched_device);
|
ssdpDiscover(s_ssdp6, 1, searched_device);
|
||||||
|
|
||||||
|
@ -1639,8 +1680,10 @@ quit:
|
||||||
free(serv->location);
|
free(serv->location);
|
||||||
free(serv);
|
free(serv);
|
||||||
}
|
}
|
||||||
|
#ifndef NO_BACKGROUND_NO_PIDFILE
|
||||||
if(unlink(pidfilename) < 0)
|
if(unlink(pidfilename) < 0)
|
||||||
syslog(LOG_ERR, "unlink(%s): %m", pidfilename);
|
syslog(LOG_ERR, "unlink(%s): %m", pidfilename);
|
||||||
|
#endif
|
||||||
closelog();
|
closelog();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ extern struct lan_addr_list lan_addrs;
|
||||||
int
|
int
|
||||||
AddDropMulticastMembership(int s, struct lan_addr_s * lan_addr, int ipv6, int drop)
|
AddDropMulticastMembership(int s, struct lan_addr_s * lan_addr, int ipv6, int drop)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
struct ip_mreq imr; /* Ip multicast membership */
|
struct ip_mreq imr; /* Ip multicast membership */
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
struct ipv6_mreq mr;
|
struct ipv6_mreq mr;
|
||||||
|
@ -56,21 +57,21 @@ AddDropMulticastMembership(int s, struct lan_addr_s * lan_addr, int ipv6, int dr
|
||||||
if(setsockopt(s, IPPROTO_IPV6, drop ? IPV6_LEAVE_GROUP : IPV6_JOIN_GROUP,
|
if(setsockopt(s, IPPROTO_IPV6, drop ? IPV6_LEAVE_GROUP : IPV6_JOIN_GROUP,
|
||||||
&mr, sizeof(struct ipv6_mreq)) < 0)
|
&mr, sizeof(struct ipv6_mreq)) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "setsockopt(udp, %s)(%s, %s): %m",
|
syslog(LOG_ERR, "setsockopt(s=%d, %s)(%s, %s): %m",
|
||||||
drop ? "IPV6_LEAVE_GROUP" : "IPV6_JOIN_GROUP",
|
s, drop ? "IPV6_LEAVE_GROUP" : "IPV6_JOIN_GROUP",
|
||||||
LL_SSDP_MCAST_ADDR,
|
LL_SSDP_MCAST_ADDR,
|
||||||
lan_addr->ifname);
|
lan_addr->ifname);
|
||||||
return -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
inet_pton(AF_INET6, SL_SSDP_MCAST_ADDR, &mr.ipv6mr_multiaddr);
|
inet_pton(AF_INET6, SL_SSDP_MCAST_ADDR, &mr.ipv6mr_multiaddr);
|
||||||
if(setsockopt(s, IPPROTO_IPV6, drop ? IPV6_LEAVE_GROUP : IPV6_JOIN_GROUP,
|
if(setsockopt(s, IPPROTO_IPV6, drop ? IPV6_LEAVE_GROUP : IPV6_JOIN_GROUP,
|
||||||
&mr, sizeof(struct ipv6_mreq)) < 0)
|
&mr, sizeof(struct ipv6_mreq)) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "setsockopt(udp, %s)(%s, %s): %m",
|
syslog(LOG_ERR, "setsockopt(s=%d, %s)(%s, %s): %m",
|
||||||
drop ? "IPV6_LEAVE_GROUP" : "IPV6_JOIN_GROUP",
|
s, drop ? "IPV6_LEAVE_GROUP" : "IPV6_JOIN_GROUP",
|
||||||
SL_SSDP_MCAST_ADDR,
|
SL_SSDP_MCAST_ADDR,
|
||||||
lan_addr->ifname);
|
lan_addr->ifname);
|
||||||
return -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -89,8 +90,8 @@ AddDropMulticastMembership(int s, struct lan_addr_s * lan_addr, int ipv6, int dr
|
||||||
if (setsockopt(s, IPPROTO_IP, drop ? IP_DROP_MEMBERSHIP : IP_ADD_MEMBERSHIP,
|
if (setsockopt(s, IPPROTO_IP, drop ? IP_DROP_MEMBERSHIP : IP_ADD_MEMBERSHIP,
|
||||||
(void *)&imr, sizeof(struct ip_mreq)) < 0)
|
(void *)&imr, sizeof(struct ip_mreq)) < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "setsockopt(udp, %s)(%s): %m",
|
syslog(LOG_ERR, "setsockopt(s=%d, %s)(%s): %m",
|
||||||
drop ? "IP_DROP_MEMBERSHIP" : "IP_ADD_MEMBERSHIP",
|
s, drop ? "IP_DROP_MEMBERSHIP" : "IP_ADD_MEMBERSHIP",
|
||||||
lan_addr->ifname);
|
lan_addr->ifname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +99,7 @@ AddDropMulticastMembership(int s, struct lan_addr_s * lan_addr, int ipv6, int dr
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue