miniupnpc-libevent: set multicast TTL to 2

This commit is contained in:
Thomas Bernard 2015-07-22 15:52:33 +02:00
parent 1512081a40
commit 4be2f4c9b5
2 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpc-libevent.c,v 1.25 2015/02/05 17:56:38 nanard Exp $ */ /* $Id: miniupnpc-libevent.c,v 1.27 2015/07/22 13:51:09 nanard Exp $ */
/* miniupnpc-libevent /* miniupnpc-libevent
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr> * Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -721,11 +721,18 @@ int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif,
p->ready_cb = ready_cb; p->ready_cb = ready_cb;
p->soap_cb = soap_cb; p->soap_cb = soap_cb;
p->cb_data = cb_data; p->cb_data = cb_data;
p->ttl = 2;
/* open the socket for SSDP */ /* open the socket for SSDP */
p->ssdp_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); p->ssdp_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(p->ssdp_socket < 0) { if(p->ssdp_socket < 0) {
return UPNPC_ERR_SOCKET_FAILED; return UPNPC_ERR_SOCKET_FAILED;
} }
/* set multicast TTL */
if(setsockopt(p->ssdp_socket, IPPROTO_IP, IP_MULTICAST_TTL, &p->ttl, sizeof(p->ttl) < 0))
{
/* not a fatal error */
debug_printf("setsockopt(%d, ..., IP_MULTICAST_TTL, ...) FAILED\n", p->ssdp_socket);
}
/* set REUSEADDR */ /* set REUSEADDR */
#ifdef _WIN32 #ifdef _WIN32
if(setsockopt(p->ssdp_socket, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt)) < 0) { if(setsockopt(p->ssdp_socket, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt)) < 0) {

View File

@ -1,6 +1,6 @@
/* $Id: miniupnpc-libevent.h,v 1.11 2014/12/02 13:33:42 nanard Exp $ */ /* $Id: miniupnpc-libevent.h,v 1.13 2015/07/22 13:48:37 nanard Exp $ */
/* miniupnpc-libevent /* miniupnpc-libevent
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr> * Copyright (c) 2008-2015, Thomas BERNARD <miniupnp@free.fr>
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
@ -88,6 +88,7 @@ struct upnpc {
#endif /* ENABLE_UPNP_EVENTS */ #endif /* ENABLE_UPNP_EVENTS */
char * local_address; char * local_address;
uint16_t local_port; uint16_t local_port;
unsigned char ttl;
}; };
int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif, int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif,