summaryrefslogtreecommitdiffstats
path: root/src/host/osmocon/osmocon.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-03-30 09:50:32 +0800
committerHarald Welte <laforge@gnumonks.org>2010-03-30 09:50:32 +0800
commited9901d842ed4810cf4e503829541ec4407c9619 (patch)
treee43b65ffc1de2ecc48b323a4fee8e23aa4e6ba5b /src/host/osmocon/osmocon.c
parentac7715a2d5be6344ce7c38bd7fb7bc834bf9cad8 (diff)
osmocon: calcluate unix domain socket length in a portable way
Let's hope this concept (as seen in Xorg sources) is portable enough to calculate the length of the sockaddr_un properly on all architectures.
Diffstat (limited to 'src/host/osmocon/osmocon.c')
-rw-r--r--src/host/osmocon/osmocon.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index f934dd77..8ed3a6d2 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -615,6 +615,7 @@ static int register_tool_server(struct tool_server *ts,
{
struct bsc_fd *bfd = &ts->bfd;
struct sockaddr_un local;
+ unsigned int namelen;
int rc;
bfd->fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -628,8 +629,20 @@ static int register_tool_server(struct tool_server *ts,
strncpy(local.sun_path, path, sizeof(local.sun_path));
local.sun_path[sizeof(local.sun_path) - 1] = '\0';
unlink(local.sun_path);
- rc = bind(bfd->fd, (struct sockaddr *) &local,
- sizeof(local.sun_family) + strlen(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);