Adding TCP keepalive support to a daemon started by inetd

I had a problem with the nbdswapd daemon used in LTSP to provide swap space for the thin clients using an nbd. This daemon is started by inetd whenever a client connects to a specific port of the LTSP server. The daemon generates a file (in /tmp with a random name by default) and uses it as a swapfile to serve the client's swap requirement. The problem is that (by default) the server does not notice, when the client crashes or reboots, thus these swapfiles are never recycled and eat up free space in /tmp. I've found the solution to this in an edubuntu-devel mailing list post. You can add TCP keepalive detection to any TCP daemon by running it through tcpd and adding a keepalive option to hosts.allow for that daemon. You can read a nice howto on TCP Keepalive at TLDP.