Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix-wizards Subject: Re: 4.2bsd IPC interface Message-ID: <1976@umcp-cs.UUCP> Date: Fri, 25-Oct-85 02:14:39 EDT Article-I.D.: umcp-cs.1976 Posted: Fri Oct 25 02:14:39 1985 Date-Received: Sat, 26-Oct-85 06:16:08 EDT References: <2192@brl-tgr.ARPA> <1009@oddjob.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 67 Note that setsockopt()s are preferable to ioctl()s on sockets, if the operation is socket-specific; and all the more so if the operation is protocol specific as well. E.g., I might write something like this: int on = 1; ... /* * Get a socket and bind it to our address, so that we may * begin accepting connections. Turn on delayed accepts so * that new connections are not acknowledged by the kernel * until a TCP_ACCEPT operation is done. (Connections may * be silently ignored by simply closing the new socket, * or actively rejected by doing a TCP_ACCEPT with a value * of zero. Or perhaps you may wish to do this another way.) */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) error(1, errno, "socket"); if (setsockopt(s, IPPROTO_TCP, TCP_DELAYEDACCEPT, (caddr_t)&on, sizeof on)) error(1, errno, "setsockopt (TCP_DELAYEDACCEPT)"); if (bind(s, (caddr_t)&myaddr, sizeof myaddr)) error(1, errno, "bind"); if (listen(s, 5)) error(1, errno, "listen"); for (;;) { client = accept(s, (caddr_t)&sin, sizeof sin); if (client < 0) { if (errno == EINTR) /* ick */ continue; error(0, errno, "accept"); continue; } /* * Fiddle with `sin' to decide whether we are willing * to accept the connection. If not, actively reject it. */ if (badclient(&sin)) { int off = 0; if (setsockopt(client, IPPROTO_TCP, TCP_ACCEPT, (caddr_t)&off, sizeof off)) error(0, errno, "setsockopt (!TCP_ACCEPT)"); (void) close(client); continue; } /* * Accept it. */ if (setsockopt(client, IPPROTO_TCP, TCP_ACCEPT, (caddr_t)&on, sizeof on)) { error(0, errno, "setsockopt (TCP_ACCEPT)"); (void) close(client); continue; } /* * Connection has now been accepted and communication is * possible. */ ... } This code is quite feasible and would not take much work on the kernel, now that 4.3BSD allows socket operations at the protocol levels. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu