home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!think.com!spdcc!dirtydog.ima.isc.com!newsserver.pixel.kodak.com!sisd!obz
- From: obz@sisd.kodak.com (Orest Zborowski COMP)
- Subject: Re: Problems with domain sockets in porting lpr
- Message-ID: <1992Aug28.010411.28133@sisd.kodak.com>
- Organization: Printer Products Eastman Kodak
- X-Newsreader: Tin 1.1 PL5
- References: <1992Aug27.165912.24167@bnr.ca>
- Date: Fri, 28 Aug 92 01:04:11 GMT
- Lines: 44
-
- Corey Minyard (minyard@crchh453.bnr.ca) wrote:
- >I have ported plp (a public lpr spooling package) to linux but I have
- >experienced a problem with domain sockets. If I do the following:
- >
- ...
- >
- > if (bind(s, &saddr, sizeof(saddr)) < 0)
- > {
- > error...
- >
- >The bind will fail. I turned on socket debugging and found it was getting
- >an invalid length. It turns out if you pass "sizeof(saddr)" to bind
- >(or connect) if fails. I looked in the kernel, and that is what it was
- >coded to do.
- >
- >Is this behavior correct? I changed the size to be
- >
- > sizeof(saddr.sun_family) + strlen(filename)
- >
- >and it worked just fine. The documentation I have on domain sockets
- >mentions nothing about this.
- >
- >----------------------------------------------------------------------
- >
- >Corey Minyard
- >minyard@bnr.ca
-
- i based the implementation on the book "unix network programming" by
- w. richard stevens (1990), a fine text for this sort of thing. in it
- it explicitly states that the filename in the unix socket struct is
- not null terminated (i.e. not expected to be), so you have to explicitly
- tell it how large the address is by adding the length of the name to
- the size of the family member. most people never use names of length 108
- (which is the maximum), and they use strcpy (which copies the null), so
- its safe to use strlen(). in fact, its bad practice to pass more than
- 14 bytes (which is why most sockets are built in /tmp) due to some of
- the other system calls. i found the strlen form in every piece of code
- i found which used unix sockets (including x11), so i'm pretty confident
- it's correct.
-
- zorst
- --
- zorst (orest zborowski)
- [obz@raster.Kodak.COM]
-