diff options
author | Harald Welte <laforge@gnumonks.org> | 2018-09-06 15:09:28 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-09-06 16:16:07 +0200 |
commit | fcfe20d3e007292e6c4c641e40d571e8ab416322 (patch) | |
tree | c9b98b07d1bb44a6ad9e90a0f086f27b8c950f7a /src/host/layer23/src/mobile | |
parent | 855cea63180d6564cf3a5c637bb92e405c7b6841 (diff) |
layer23: Use osmo_sock_unix_init_ofd() from libosmocore
We don't need to hand-code unix domain socket initialization but
can simply use our library function for it. As an added benefit,
the library code already contains corner case handling for non-NUL
terminated unix domain socket path.
Change-Id: I57c724c78dbbbce0546ebe914e370f32c8c89703
Diffstat (limited to 'src/host/layer23/src/mobile')
-rw-r--r-- | src/host/layer23/src/mobile/mncc_sock.c | 63 |
1 files changed, 3 insertions, 60 deletions
diff --git a/src/host/layer23/src/mobile/mncc_sock.c b/src/host/layer23/src/mobile/mncc_sock.c index 39eb7bcc..d7d56cc0 100644 --- a/src/host/layer23/src/mobile/mncc_sock.c +++ b/src/host/layer23/src/mobile/mncc_sock.c @@ -1,6 +1,6 @@ /* mncc_sock.c: Tie the MNCC interface to a unix domain socket */ -/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> +/* (C) 2008-2011,2018 by Harald Welte <laforge@gnumonks.org> * (C) 2009,2011 by Andreas Eversberg <andreas@eversberg.eu> * All Rights Reserved * @@ -34,6 +34,7 @@ #include <osmocom/core/select.h> #include <osmocom/core/timer.h> #include <osmocom/core/msgb.h> +#include <osmocom/core/socket.h> #include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/bb/common/logging.h> @@ -80,9 +81,6 @@ void mncc_sock_write_pending(struct mncc_sock_state *state) state->conn_bfd.when |= BSC_FD_WRITE; } -/* 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; @@ -268,7 +266,7 @@ struct mncc_sock_state *mncc_sock_init(void *inst, const char *name) bfd = &state->listen_bfd; - rc = osmo_unixsock_listen(bfd, SOCK_SEQPACKET, name); + rc = osmo_sock_unix_init_ofd(bfd, SOCK_SEQPACKET, 0, name, OSMO_SOCK_F_BIND); if (rc < 0) { LOGP(DMNCC, LOGL_ERROR, "Could not create unix socket: %s\n", strerror(errno)); @@ -276,18 +274,9 @@ struct mncc_sock_state *mncc_sock_init(void *inst, const char *name) return NULL; } - bfd->when = BSC_FD_READ; bfd->cb = mncc_sock_accept; bfd->data = state; - rc = osmo_fd_register(bfd); - if (rc < 0) { - LOGP(DMNCC, LOGL_ERROR, "Could not register listen fd: %d\n", rc); - close(bfd->fd); - talloc_free(state); - return NULL; - } - return state; } @@ -299,49 +288,3 @@ void mncc_sock_exit(struct mncc_sock_state *state) close(state->listen_bfd.fd); talloc_free(state); } - -/* 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; - osmo_strlcpy(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; -} |