From: Ruben Kerkhof Date: Sat, 2 Apr 2016 14:29:59 +0000 (+0200) Subject: gmond plugin: check remaining setsockopt calls X-Git-Tag: collectd-5.6.0~366 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=48cf5a7b088e4a0a5f8fb06baaa1b6f43b9dbfec;p=collectd.git gmond plugin: check remaining setsockopt calls Fixes CID #38112 --- diff --git a/src/gmond.c b/src/gmond.c index 1aa95d57..67e0406c 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -323,14 +323,27 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ } loop = 1; - setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_MULTICAST_LOOP, + status = setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void *) &loop, sizeof (loop)); + if (status != 0) + { + char errbuf[1024]; + WARNING ("gmond plugin: setsockopt(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } memset (&mreq, 0, sizeof (mreq)); mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr; mreq.imr_interface.s_addr = htonl (INADDR_ANY); - setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, + + status = setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *) &mreq, sizeof (mreq)); + if (status != 0) + { + char errbuf[1024]; + WARNING ("gmond plugin: setsockopt(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } } /* if (ai_ptr->ai_family == AF_INET) */ else if (ai_ptr->ai_family == AF_INET6) { @@ -347,15 +360,27 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ } loop = 1; - setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, + status = setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (void *) &loop, sizeof (loop)); + if (status != 0) + { + char errbuf[1024]; + WARNING ("gmond plugin: setsockopt(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } memset (&mreq, 0, sizeof (mreq)); memcpy (&mreq.ipv6mr_multiaddr, &addr->sin6_addr, sizeof (addr->sin6_addr)); mreq.ipv6mr_interface = 0; /* any */ - setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, + status = setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (void *) &mreq, sizeof (mreq)); + if (status != 0) + { + char errbuf[1024]; + WARNING ("gmond plugin: setsockopt(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } } /* if (ai_ptr->ai_family == AF_INET6) */ sockets_num++;