diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2018-08-01 12:43:08 +0200 |
---|---|---|
committer | Philipp Maier <pmaier@sysmocom.de> | 2018-08-02 11:19:38 +0200 |
commit | 0659c5d2f3e7653668838a2162ec72efb67ca68e (patch) | |
tree | c820f9e5abc1f3682b925f0b4135a6fe9812edb8 | |
parent | 5a7740d1dbefcb0116a1936da3f96960250fd849 (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.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/socket.c b/src/socket.c index dc5590c0..0a4e34cd 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) { |