From: Florian Forster Date: Sat, 5 Dec 2015 21:23:05 +0000 (+0100) Subject: libcollectdclient: Check return value of setsockopt(). X-Git-Tag: collectd-5.5.1~24^2~5 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f3e1b0e73ce355fc74e823c1123e2d50efb49176;p=collectd.git libcollectdclient: Check return value of setsockopt(). Coverity CID 37944. Signed-off-by: Florian Forster --- diff --git a/src/libcollectdclient/network.c b/src/libcollectdclient/network.c index 6b6450c9..6733cda4 100644 --- a/src/libcollectdclient/network.c +++ b/src/libcollectdclient/network.c @@ -148,7 +148,6 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ if (ai_ptr->ai_family == AF_INET) { - struct sockaddr_in *addr = (struct sockaddr_in *) ai_ptr->ai_addr; int optname; @@ -157,9 +156,8 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ else optname = IP_TTL; - setsockopt (srv->fd, IPPROTO_IP, optname, - &srv->ttl, - sizeof (srv->ttl)); + status = setsockopt (srv->fd, IPPROTO_IP, optname, + &srv->ttl, sizeof (srv->ttl)); } else if (ai_ptr->ai_family == AF_INET6) { @@ -172,9 +170,15 @@ static int server_open_socket (lcc_server_t *srv) /* {{{ */ else optname = IPV6_UNICAST_HOPS; - setsockopt (srv->fd, IPPROTO_IPV6, optname, - &srv->ttl, - sizeof (srv->ttl)); + status = setsockopt (srv->fd, IPPROTO_IPV6, optname, + &srv->ttl, sizeof (srv->ttl)); + } + if (status != 0) + { + /* setsockopt failed. */ + close (srv->fd); + srv->fd = -1; + continue; } srv->sa = malloc (ai_ptr->ai_addrlen);