layer23: use correct sizeof(sockaddr) for connecting to L1CTL socket
authorDavid Wilson <dw@botanicus.net>
Thu, 9 Dec 2010 03:33:02 +0000 (03:33 +0000)
committerHarald Welte <laforge@gnumonks.org>
Sat, 11 Dec 2010 03:31:57 +0000 (11:31 +0800)
connect's addrlen should be sizeof(local), not the contained path's length.

With the previous code, on OS X connect() will fail with ENOENT.

This permits layer23 to work on OS X using the pl2303 driver,
/dev/tty.usbserial , MacPorts arm-elf-gcc and RANLIB=arm-elf-ranlib

Signed-off-by: Harald Welte <laforge@gnumonks.org>
src/host/layer23/src/common/l1l2_interface.c

index e72b86e..74c8875 100644 (file)
@@ -118,9 +118,10 @@ int layer2_open(struct osmocom_ms *ms, const char *socket_path)
        local.sun_path[sizeof(local.sun_path) - 1] = '\0';
 
        rc = connect(ms->l2_wq.bfd.fd, (struct sockaddr *) &local,
-                    sizeof(local.sun_family) + strlen(local.sun_path));
+                    sizeof(local));
        if (rc < 0) {
-               fprintf(stderr, "Failed to connect to '%s'.\n", local.sun_path);
+               fprintf(stderr, "Failed to connect to '%s': %s\n", local.sun_path,
+                       strerror(errno));
                close(ms->l2_wq.bfd.fd);
                return rc;
        }