[ale]simple inetd daemon

Joseph A Knapka jknapka at earthlink.net
Tue Nov 20 11:15:21 EST 2001


Chris Fowler wrote:
> 
> I need to write a simple inetd daemon that will manage only rshd and telnetd.  I know a
> bit of how it works.  I need to know how 1 daemon can listen to multiple sockets.

Easy, use select():
(Pseudo C code)

s1 = socket(...);
s2 = socket(...);
bind(s1,<listen port 1>);
bind(s2,<listen port 2>);
listen(s1,...);
listen(s2,...);

fd_set fds = <fd_set containing s1 and s2>;

n = select(&fds,0,0,timeout);

/* Check fds for readable sockets... */
if (s1 is readable) {
	new_socket = accept(s1);
	fork(or whatever);
}
if (s2 is readable) {
	new_socket = accept(s2);
	fork(or whatever);
}

HTH,

-- Joe
# "This torch I bear is scorching me; Buffy's
   laughing, I've no doubt! I hope she fries,
   I'm free if that bitch dies... I'd better
   help her out." -- Spike, OMWF, BtVS

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list