home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / linux / 9238 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.1 KB  |  56 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!think.com!spdcc!dirtydog.ima.isc.com!newsserver.pixel.kodak.com!sisd!obz
  3. From: obz@sisd.kodak.com (Orest Zborowski COMP)
  4. Subject: Re: Problems with domain sockets in porting lpr
  5. Message-ID: <1992Aug28.010411.28133@sisd.kodak.com>
  6. Organization: Printer Products Eastman Kodak
  7. X-Newsreader: Tin 1.1 PL5
  8. References: <1992Aug27.165912.24167@bnr.ca>
  9. Date: Fri, 28 Aug 92 01:04:11 GMT
  10. Lines: 44
  11.  
  12. Corey Minyard (minyard@crchh453.bnr.ca) wrote:
  13. >I have ported plp (a public lpr spooling package) to linux but I have
  14. >experienced a problem with domain sockets.  If I do the following:
  15. >
  16.     ...
  17. >      
  18. >      if (bind(s, &saddr, sizeof(saddr)) < 0)
  19. >      {
  20. >         error...
  21. >
  22. >The bind will fail.  I turned on socket debugging and found it was getting
  23. >an invalid length.  It turns out if you pass "sizeof(saddr)" to bind
  24. >(or connect) if fails.  I looked in the kernel, and that is what it was
  25. >coded to do.
  26. >
  27. >Is this behavior correct?  I changed the size to be 
  28. >
  29. >   sizeof(saddr.sun_family) + strlen(filename)
  30. >
  31. >and it worked just fine.  The documentation I have on domain sockets
  32. >mentions nothing about this.
  33. >
  34. >----------------------------------------------------------------------
  35. >
  36. >Corey Minyard
  37. >minyard@bnr.ca
  38.  
  39. i based the implementation on the book "unix network programming" by 
  40. w. richard stevens (1990), a fine text for this sort of thing. in it
  41. it explicitly states that the filename in the unix socket struct is
  42. not null terminated (i.e. not expected to be), so you have to explicitly
  43. tell it how large the address is by adding the length of the name to
  44. the size of the family member. most people never use names of length 108
  45. (which is the maximum), and they use strcpy (which copies the null), so
  46. its safe to use strlen(). in fact, its bad practice to pass more than
  47. 14 bytes (which is why most sockets are built in /tmp) due to some of
  48. the other system calls. i found the strlen form in every piece of code
  49. i found which used unix sockets (including x11), so i'm pretty confident
  50. it's correct.
  51.  
  52. zorst
  53. -- 
  54. zorst (orest zborowski)
  55. [obz@raster.Kodak.COM]
  56.