the /tmp/osmoncon* sockets created by osmocon are created one character too short.
willem
fix:
diff --git a/src/host/layer23/src/main.c b/src/host/layer23/src/main.c index 8e76e8b..9e37fbf 100644 --- a/src/host/layer23/src/main.c +++ b/src/host/layer23/src/main.c @@ -244,7 +244,7 @@ int main(int argc, char **argv) local.sun_path[sizeof(local.sun_path) - 1] = '\0';
rc = connect(ms->wq.bfd.fd, (struct sockaddr *) &local, - sizeof(local.sun_family) + strlen(local.sun_path)); + sizeof(local.sun_family) + strlen(local.sun_path) + 1); if (rc < 0) { fprintf(stderr, "Failed to connect to '%s'.\n", local.sun_path); exit(1); diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c index f934dd7..b361eb1 100644 --- a/src/host/osmocon/osmocon.c +++ b/src/host/osmocon/osmocon.c @@ -629,7 +632,7 @@ static int register_tool_server(struct tool_server *ts, 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)); + sizeof(local.sun_family) + strlen(local.sun_path) + 1); if (rc != 0) { fprintf(stderr, "Failed to bind the unix domain socket. '%s'\n", local.sun_path); diff --git a/src/host/osmocon/osmoload.c b/src/host/osmocon/osmoload.c index ecee8b3..fdf417a 100644 --- a/src/host/osmocon/osmoload.c +++ b/src/host/osmocon/osmoload.c @@ -128,7 +128,7 @@ loader_connect(const char *socket_path) { }
rc = connect(conn->fd, (struct sockaddr *) &local, - sizeof(local.sun_family) + strlen(local.sun_path)); + sizeof(local.sun_family) + strlen(local.sun_path) + 1); if (rc < 0) { fprintf(stderr, "Failed to connect to '%s'.\n", local.sun_path); exit(1);
On 2010-03-29 12:52:11, Holger Freyther wrote:
On Monday 29 March 2010 12:39:48 willem wrote:
the /tmp/osmoncon* sockets created by osmocon are created one character too short.
Can you explain?
the sockaddr struct for named sockets is defined like this ( on my mac )
struct sockaddr_un { unsigned char sun_len; /* sockaddr len including null */ sa_family_t sun_family; /* [XSI] AF_UNIX */ char sun_path[104]; /* [XSI] path name (gag) */ };
the sun_len value is ignored. but the total length of the struct passed to bind / connect should include it.
without this fix, the second time i run './osmocon' it will complain: Failed to bind the unix domain socket since it tried to unlink the correct name, but called bind with a one char too short name.
willem
On 2010-03-29 16:39:31, willem wrote:
On 2010-03-29 12:52:11, Holger Freyther wrote:
On Monday 29 March 2010 12:39:48 willem wrote:
the /tmp/osmoncon* sockets created by osmocon are created one character too short.
Can you explain?
the sockaddr struct for named sockets is defined like this ( on my mac )
struct sockaddr_un { unsigned char sun_len; /* sockaddr len including null */ sa_family_t sun_family; /* [XSI] AF_UNIX */ char sun_path[104]; /* [XSI] path name (gag) */ };
the sun_len value is ignored. but the total length of the struct passed to bind / connect should include it.
without this fix, the second time i run './osmocon' it will complain: Failed to bind the unix domain socket since it tried to unlink the correct name, but called bind with a one char too short name.
now checked cygwin headers. there the sun_len member is missing. the more portable way would be to use SUN_LEN(&local)
i also noticed that the cygwin version of 'bind' apparently ignores the socklen_t parameter. and internally uses strlen to find the length.
on freebsd and osx you should use the SUN_LEN macro to pass the correct length of the sockaddr_un struct.
willem
On Mon, Mar 29, 2010 at 09:59:25PM +0200, willem wrote:
on freebsd and osx you should use the SUN_LEN macro to pass the correct length of the sockaddr_un struct.
I have now committed a change using the same method as is used in Xorg.
You still might need to do some || defined(__MACOS__) or the like, please test and submit a patch incremental to the current master version.
baseband-devel@lists.osmocom.org