binding sockets

Chris Torek chris at mimsy.umd.edu
Wed Sep 19 22:55:43 AEST 1990


In article <1990Sep16.183730.18698 at athena.mit.edu>
jik at athena.mit.edu (Jonathan I. Kamens) writes:
>  No, actually, the namelen parameter one passes to bind() should be the
>sizeof the sockaddr structure being passed into it ...

Well, it `should' be 2+strlen(path), or (in 4.3BSD-reno) SUN_LEN:

>   name.sun_family = AF_UNIX;
>   strcpy(name.sun_path, "/tmp/testsocket");
>   bind(s, &name, sizeof(name));

    bind(s, &name, SUN_LEN(name));

Since the size of a sockaddr_un is carefully set to fill one mbuf, using
sizeof(name) will work, and you can `cheat' and just use sizeof(name): the
embedded '\0' will (must) be within the resulting single mbuf allocated
by the bind() system call and the name lookup will work.  But the
documentation (such as it is) says that the name length `should' be
exactly right, and a future version of the system might require this.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.programmer mailing list