home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.misc:4612 comp.sys.next.programmer:7797
- Newsgroups: comp.unix.misc,comp.sys.next.programmer
- Path: sparky!uunet!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!cs.tu-berlin.de!net
- From: net@cs.tu-berlin.de (Oliver Laumann)
- Subject: Re: Need help with setsockopt
- Message-ID: <1992Dec17.112537.14836@cs.tu-berlin.de>
- Sender: news@cs.tu-berlin.de
- Organization: Technical University of Berlin, Germany
- References: <1992Dec17.033142.17836@dartvax.dartmouth.edu>
- Date: Thu, 17 Dec 1992 11:25:37 GMT
- Lines: 23
-
- lusty@fermat.dartmouth.edu (Diana Shoemaker) writes:
- > Specifically, the two lines that attempt to set socket options, fail to
- > set the options, i.e., they get a return value of -1.
- >
- > setsockopt(id->fd, SOL_SOCKET, SO_LINGER, 0, 0)
- > setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, 0, 0)
-
- The "optval" and "optlen" arguments you specified are wrong. SO_LINGER
- requires the optval argument to be a pointer to a "struct linger", and
- SO_REUSEADDR expects a pointer to an "int" indicating whether you want
- to enable or disable the option. The final optlen argument always gives
- the size of the option value:
-
- int on = 1;
- struct linger l;
-
- l.l_onoff = 1;
- l.l_linger = 60; /* linger time in seconds */
-
- if (setsockopt(id->fd, SOL_SOCKET, SO_LINGER, (char*)&l, sizeof(l)) == -1)
- error...
- if (setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)) == -1)
- error...
-