home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / misc / 4612 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.4 KB  |  36 lines

  1. Xref: sparky comp.unix.misc:4612 comp.sys.next.programmer:7797
  2. Newsgroups: comp.unix.misc,comp.sys.next.programmer
  3. Path: sparky!uunet!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!cs.tu-berlin.de!net
  4. From: net@cs.tu-berlin.de (Oliver Laumann)
  5. Subject: Re: Need help with setsockopt
  6. Message-ID: <1992Dec17.112537.14836@cs.tu-berlin.de>
  7. Sender: news@cs.tu-berlin.de
  8. Organization: Technical University of Berlin, Germany
  9. References: <1992Dec17.033142.17836@dartvax.dartmouth.edu>
  10. Date: Thu, 17 Dec 1992 11:25:37 GMT
  11. Lines: 23
  12.  
  13. lusty@fermat.dartmouth.edu (Diana Shoemaker) writes:
  14. > Specifically, the two lines that attempt to set socket options, fail to
  15. > set the options, i.e., they get a return value of -1.
  16. > setsockopt(id->fd, SOL_SOCKET, SO_LINGER, 0, 0)
  17. > setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, 0, 0)
  18.  
  19. The "optval" and "optlen" arguments you specified are wrong.  SO_LINGER
  20. requires the optval argument to be a pointer to a "struct linger", and
  21. SO_REUSEADDR expects a pointer to an "int" indicating whether you want
  22. to enable or disable the option.  The final optlen argument always gives
  23. the size of the option value:
  24.  
  25. int on = 1;
  26. struct linger l;
  27.  
  28. l.l_onoff = 1;
  29. l.l_linger = 60;   /* linger time in seconds */
  30.  
  31. if (setsockopt(id->fd, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof(l)) == -1)
  32.     error...
  33. if (setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)) == -1)
  34.     error...
  35.