Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 96 03:18:14 +0100
From:      Jean-Marc Zucconi <jmz@cabri.obs-besancon.fr>
To:        freebsd-current@freebsd.org
Subject:   socket (AF_UNIX) bug
Message-ID:  <9610210218.AA09736@cabri.obs-besancon.fr>

next in thread | raw e-mail | index | archive | help
The following code creates a socket whose name is 1 char too
short. A workaround is to add 1 to addrlen before calling bind, but I
think that the code should  work as is. 

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>

main ()
{
    int s;
    struct sockaddr_un sockaddr;
    char path[256];
    int addrlen;

    strcpy (path, "/tmp/zxyz");
    unlink (path);
    s = socket (AF_UNIX, SOCK_STREAM, 0);
    memset ((void *)&sockaddr, 0, sizeof(sockaddr));
    sockaddr.sun_family = AF_UNIX;
    strncpy (sockaddr.sun_path, path, sizeof(sockaddr.sun_path));
    addrlen = sizeof(sockaddr.sun_family) + strlen(path);
    if (bind (s, (struct sockaddr *)&sockaddr, addrlen) < 0)
	perror ("bind");
    system ("ls -l /tmp/zx*");
    close (s);
}

Jean-Marc
 _____________________________________________________________________________
 Jean-Marc Zucconi       Observatoire de Besancon       F 25010 Besancon cedex
                   PGP Key: finger jmz@cabri.obs-besancon.fr
 =============================================================================



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9610210218.AA09736>