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/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/10802
Change subject: osmocon: Use osmo_sock_unix_init_ofd() from libosmocore
......................................................................
osmocon: 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: I3ab69a971be555c9f9b5b7a7e5da53008a119504
---
M src/host/osmocon/osmocon.c
1 file changed, 4 insertions(+), 35 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/02/10802/1
diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index 6075e61..139c2db 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -1,6 +1,6 @@
/* osmocon */
-/* (C) 2010 by Harald Welte <laforge at gnumonks.org>
+/* (C) 2010,2018 by Harald Welte <laforge at gnumonks.org>
* (C) 2010 by Holger Hans Peter Freyther <zecke at selfish.org>
* (C) 2010 by Steve Markgraf <steve at steve-m.de>
*
@@ -45,6 +45,7 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/application.h>
+#include <osmocom/core/socket.h>
#include <arpa/inet.h>
@@ -1333,46 +1334,14 @@
uint8_t dlci)
{
struct osmo_fd *bfd = &ts->bfd;
- struct sockaddr_un local;
- unsigned int namelen;
int rc;
- bfd->fd = socket(AF_UNIX, SOCK_STREAM, 0);
-
- if (bfd->fd < 0) {
+ rc = osmo_sock_unix_init_ofd(bfd, SOCK_STREAM, 0, path, OSMO_SOCK_F_BIND);
+ if (rc < 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;
- }
-
bfd->when = BSC_FD_READ;
bfd->cb = tool_accept;
bfd->data = ts;
--
To view, visit https://gerrit.osmocom.org/10802
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3ab69a971be555c9f9b5b7a7e5da53008a119504
Gerrit-Change-Number: 10802
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180906/7b4ba0dd/attachment.htm>