From 6bf84dc834589b5e50891fc79199f9299ec1bbd8 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 23 May 2014 12:07:39 +0200 Subject: [PATCH] miniupnpd/minissdp.c: clean SendSSDPbyebye() --- miniupnpd/minissdp.c | 59 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/miniupnpd/minissdp.c b/miniupnpd/minissdp.c index f9f4380..12b63c5 100644 --- a/miniupnpd/minissdp.c +++ b/miniupnpd/minissdp.c @@ -1055,10 +1055,10 @@ ProcessSSDPData(int s, const char *bufr, int n, } static int -SendSSDPbyebye(int s, const struct sockaddr * dest, +SendSSDPbyebye(int s, const struct sockaddr * dest, socklen_t destlen, + const char * dest_str, const char * nt, const char * suffix, - const char * usn1, const char * usn2, const char * usn3, - int ipv6) + const char * usn1, const char * usn2, const char * usn3) { int n, l; char bufr[SSDP_PACKET_MAX_LEN]; @@ -1074,9 +1074,8 @@ SendSSDPbyebye(int s, const struct sockaddr * dest, "BOOTID.UPNP.ORG: %u\r\n" /* UDA v1.1 */ "CONFIGID.UPNP.ORG: %u\r\n" /* UDA v1.1 */ "\r\n", - ipv6 ? "[" LL_SSDP_MCAST_ADDR "]" : SSDP_MCAST_ADDR, - SSDP_PORT, - nt, suffix, /* NT: */ + dest_str, SSDP_PORT, /* HOST : */ + nt, suffix, /* NT: */ usn1, usn2, usn3, suffix, /* USN: */ upnp_bootid, upnp_bootid, upnp_configid); if(l<0) @@ -1090,13 +1089,7 @@ SendSSDPbyebye(int s, const struct sockaddr * dest, "SendSSDPbyebye()", (unsigned)l, (unsigned)sizeof(bufr)); l = sizeof(bufr) - 1; } - n = sendto_or_schedule(s, bufr, l, 0, dest, -#ifdef ENABLE_IPV6 - ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in) -#else - sizeof(struct sockaddr_in) -#endif - ); + n = sendto_or_schedule(s, bufr, l, 0, dest, destlen); if(n < 0) { syslog(LOG_ERR, "sendto(udp_shutdown=%d): %m", s); @@ -1115,30 +1108,44 @@ SendSSDPbyebye(int s, const struct sockaddr * dest, int SendSSDPGoodbye(int * sockets, int n_sockets) { - struct sockaddr_in sockname; + struct sockaddr_in sockname4; #ifdef ENABLE_IPV6 struct sockaddr_in6 sockname6; + struct sockaddr * sockname; + socklen_t socknamelen; #endif int i, j; char ver_str[4]; int ret = 0; int ipv6 = 0; + const char * dest_str; - memset(&sockname, 0, sizeof(struct sockaddr_in)); - sockname.sin_family = AF_INET; - sockname.sin_port = htons(SSDP_PORT); - sockname.sin_addr.s_addr = inet_addr(SSDP_MCAST_ADDR); + memset(&sockname4, 0, sizeof(struct sockaddr_in)); + sockname4.sin_family = AF_INET; + sockname4.sin_port = htons(SSDP_PORT); + sockname4.sin_addr.s_addr = inet_addr(SSDP_MCAST_ADDR); #ifdef ENABLE_IPV6 memset(&sockname6, 0, sizeof(struct sockaddr_in6)); sockname6.sin6_family = AF_INET6; sockname6.sin6_port = htons(SSDP_PORT); inet_pton(AF_INET6, LL_SSDP_MCAST_ADDR, &(sockname6.sin6_addr)); +#else + dest_str = SSDP_MCAST_ADDR; #endif for(j=0; j