aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2018-08-01 12:43:08 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2018-08-02 11:19:38 +0200
commit0659c5d2f3e7653668838a2162ec72efb67ca68e (patch)
treec820f9e5abc1f3682b925f0b4135a6fe9812edb8
parent5a7740d1dbefcb0116a1936da3f96960250fd849 (diff)
socket: check return code of setsockopt
the return code of the last setsockopt() call in osmo_sock_init() is not checked. Since all other calls to setsockopt are checked, lets check this one as well. - check return code of setsockopt() and close the socket on failure Change-Id: I96dbccc3bcff35bf39979dbe0c44aadc8ce20c83
-rw-r--r--src/socket.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/socket.c b/src/socket.c
index dc5590c..0a4e34c 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -373,7 +373,14 @@ int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
return -ENODEV;
}
- setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ if (rc < 0) {
+ LOGP(DLGLOBAL, LOGL_ERROR,
+ "cannot setsockopt socket: %s:%u: %s\n", host, port,
+ strerror(errno));
+ close(sfd);
+ sfd = -1;
+ }
rc = osmo_sock_init_tail(sfd, type, flags);
if (rc < 0) {