[PATCH] openbsc[master]: mncc_sock: use osmo_sock_unix_init() from libosmocore

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Wed Jul 20 15:41:36 UTC 2016


Review at  https://gerrit.osmocom.org/555

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
---
M openbsc/src/libmsc/mncc_sock.c
1 file changed, 5 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/55/555/1

diff --git a/openbsc/src/libmsc/mncc_sock.c b/openbsc/src/libmsc/mncc_sock.c
index 6da1c56..5018daf 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>
@@ -292,12 +293,13 @@
 
 	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;
@@ -315,51 +317,5 @@
 	net->mncc_state = state;
 
 	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;
 }

-- 
To view, visit https://gerrit.osmocom.org/555
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iacfc39b6214c24084438f8fe04d03952cdc9ebc2
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list