UNIX domain addressing for 4.2bsd IPC
mogul%shasta at sri-unix.UUCP
mogul%shasta at sri-unix.UUCP
Sat Dec 10 04:46:00 AEST 1983
From: Jeff Mogul <mogul at shasta>
The primer lies, but "man 2 bind" is more truthful. You've
got to #include <sys/un.h> to get the definitions for the Unix
addressing domain, then create an appropriate sockaddr_un (limited
to 108 bytes, not 109 bytes as the declaration would imply, because
the kernel rejects sockaddrs >= MLEN and the sizeof(struct sockaddr_un)
== MLEN because the compiler short-aligns it, so passing
sizeof(struct sockaddr_un) as the length argument to bind() will
get you an error.)
By the way, don't even bother trying SOCK_DGRAM in AF_UNIX. It won't
work. If you try to use sendto/recvfrom the receiver gets a totally
blank address in "from". If you try to use accept() in the receiver
and connect()/send() in the sender, the send() fails because it thinks
you haven't yet supplied a destination address! Following connect()
by sendto() fails because "you've already supplied a destination
address"(!) Using sendto() by itself fails to wake up the receiver
from its accept().
I spent a few days staring at the kernel sources and I think the problems
with connection-based SOCK_DGRAMs (sort of a contradiction in terms
anyway) might be fixed with about 4 lines of code -- but I haven't been
brave enough to try it. The problems with unconnected DGRAMs are
deeper, but I think it's possible to provide at least a kludgey
solution. I just gave up and used AF_INET, which works more or less,
but I'm not happy.
-Jeff
P.S.: To top it all off, there's a "man 4 inet" page but no corresponding
page for the Unix domain, at least on our tape.
More information about the Comp.unix.wizards
mailing list