summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-11-26 14:39:47 +0100
committerHarald Welte <laforge@gnumonks.org>2016-11-26 17:10:29 +0100
commit456f68b16041f9cb30281e428744a12a372a5b73 (patch)
tree3027854a6797eff6ef27cec56ba4c5b52b85c172
parent487436138e3dca6a99862abc779ac5230c8f826b (diff)
mgcp_network.c: Use libosmocore socket functions
Use libosmocore osmo_sock_init_ofd() in mgcp_create_bind(), rather than using a hand-coded version using OS socket functions. The locally implemented verison of the code didn't check setsockopt() return value. Change-Id: I1de4de12245847a6d30d1bf7c91dc813d2178dee Fixes: Coverity CID 57646
-rw-r--r--openbsc/src/libmgcp/mgcp_network.c27
1 files changed, 4 insertions, 23 deletions
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index abce6e49d..a98a60fd4 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -28,10 +28,10 @@
#include <time.h>
#include <limits.h>
-#include <sys/socket.h>
#include <arpa/inet.h>
#include <osmocom/core/msgb.h>
+#include <osmocom/core/socket.h>
#include <osmocom/core/select.h>
#include <osmocom/netif/rtp.h>
@@ -884,28 +884,9 @@ static int rtp_data_trans_bts(struct osmo_fd *fd, unsigned int what)
int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port)
{
- struct sockaddr_in addr;
- int on = 1;
-
- fd->fd = socket(AF_INET, SOCK_DGRAM, 0);
- if (fd->fd < 0) {
- LOGP(DMGCP, LOGL_ERROR, "Failed to create UDP port.\n");
- return -1;
- }
-
- setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- inet_aton(source_addr, &addr.sin_addr);
-
- if (bind(fd->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- close(fd->fd);
- fd->fd = -1;
- return -1;
- }
-
- return 0;
+ return osmo_sock_init_ofd(fd, AF_INET, SOCK_DGRAM, IPPROTO_UDP,
+ source_addr, port,
+ OSMO_SOCK_F_BIND|OSMO_SOCK_F_NONBLOCK);
}
int mgcp_set_ip_tos(int fd, int tos)