aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2016-07-20 21:40:54 +0600
committerHarald Welte <laforge@gnumonks.org>2016-07-23 19:21:17 +0000
commitd091b8de21506571f64c248a7635af60cc77633c (patch)
treef05238502e9b35893353a6744dbdaeac539e32fd
parent15fcd10fde06f841c5f3e0ce4c9fded463fad470 (diff)
mncc_sock: use osmo_sock_unix_init() from libosmocore
Since the osmo_unixsock_listen() was moved to libosmocore it would be better to use the library's implementation instead of reinventing the wheel again. Change-Id: Iacfc39b6214c24084438f8fe04d03952cdc9ebc2
-rw-r--r--openbsc/src/libmsc/mncc_sock.c57
1 files changed, 5 insertions, 52 deletions
diff --git a/openbsc/src/libmsc/mncc_sock.c b/openbsc/src/libmsc/mncc_sock.c
index 6da1c5676..0efe3a156 100644
--- a/openbsc/src/libmsc/mncc_sock.c
+++ b/openbsc/src/libmsc/mncc_sock.c
@@ -32,6 +32,7 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/select.h>
+#include <osmocom/core/socket.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include <openbsc/debug.h>
@@ -76,9 +77,6 @@ int mncc_sock_from_cc(struct gsm_network *net, struct msgb *msg)
return 0;
}
-/* FIXME: move this to libosmocore */
-int osmo_unixsock_listen(struct osmo_fd *bfd, int type, const char *path);
-
static void mncc_sock_close(struct mncc_sock_state *state)
{
struct osmo_fd *bfd = &state->conn_bfd;
@@ -292,12 +290,13 @@ int mncc_sock_init(struct gsm_network *net, const char *sock_path)
bfd = &state->listen_bfd;
- rc = osmo_unixsock_listen(bfd, SOCK_SEQPACKET, sock_path);
- if (rc < 0) {
+ bfd->fd = osmo_sock_unix_init(SOCK_SEQPACKET, 0, sock_path,
+ OSMO_SOCK_F_BIND);
+ if (bfd->fd < 0) {
LOGP(DMNCC, LOGL_ERROR, "Could not create unix socket: %s: %s\n",
sock_path, strerror(errno));
talloc_free(state);
- return rc;
+ return -1;
}
bfd->when = BSC_FD_READ;
@@ -317,49 +316,3 @@ int mncc_sock_init(struct gsm_network *net, const char *sock_path)
LOGP(DMNCC, LOGL_NOTICE, "MNCC socket at %s\n", sock_path);
return 0;
}
-
-/* FIXME: move this to libosmocore */
-int osmo_unixsock_listen(struct osmo_fd *bfd, int type, const char *path)
-{
- struct sockaddr_un local;
- unsigned int namelen;
- int rc;
-
- bfd->fd = socket(AF_UNIX, type, 0);
-
- if (bfd->fd < 0) {
- fprintf(stderr, "Failed to create Unix Domain Socket.\n");
- return -1;
- }
-
- local.sun_family = AF_UNIX;
- strncpy(local.sun_path, path, sizeof(local.sun_path));
- local.sun_path[sizeof(local.sun_path) - 1] = '\0';
- unlink(local.sun_path);
-
- /* we use the same magic that X11 uses in Xtranssock.c for
- * calculating the proper length of the sockaddr */
-#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
- local.sun_len = strlen(local.sun_path);
-#endif
-#if defined(BSD44SOCKETS) || defined(SUN_LEN)
- namelen = SUN_LEN(&local);
-#else
- namelen = strlen(local.sun_path) +
- offsetof(struct sockaddr_un, sun_path);
-#endif
-
- rc = bind(bfd->fd, (struct sockaddr *) &local, namelen);
- if (rc != 0) {
- fprintf(stderr, "Failed to bind the unix domain socket. '%s'\n",
- local.sun_path);
- return -1;
- }
-
- if (listen(bfd->fd, 0) != 0) {
- fprintf(stderr, "Failed to listen.\n");
- return -1;
- }
-
- return 0;
-}