From 99fd5410bf4c1b0fb633959577a1ccbb6f23af29 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sun, 28 Jun 2020 08:00:20 +0200 Subject: [PATCH] setsockopt: always check its return value Signed-off-by: Nikos Mavrogiannopoulos --- src/main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 1b2b380c..efc983dc 100644 --- a/src/main.c +++ b/src/main.c @@ -200,8 +200,10 @@ int _listen_ports(void *pool, struct perm_cfg_st* config, y = 1; /* avoid listen on ipv6 addresses failing * because already listening on ipv4 addresses: */ - setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, - (const void *) &y, sizeof(y)); + if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, + (const void *) &y, sizeof(y)) < 0) { + perror("setsockopt(IPV6_V6ONLY) failed"); + } } #endif @@ -468,13 +470,17 @@ int y; y = 1; /* avoid listen on ipv6 addresses failing * because already listening on ipv4 addresses: */ - setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, - (const void *) &y, sizeof(y)); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, + (const void *) &y, sizeof(y)) < 0) { + perror("setsockopt(IPV6_V6ONLY) failed"); + } } #endif y = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &y, sizeof(y)); + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &y, sizeof(y)) < 0) { + perror("setsockopt(SO_REUSEADDR) failed"); + } if (GETCONFIG(s)->try_mtu) { set_mtu_disc(fd, family, 1);