[KLUG Programming] tcp connection is alive

Dirk H Bartley programming@kalamazoolinux.org
03 Nov 2003 09:35:25 -0500


Greetings

I'm using netcat in a perl script with an open2 function call.  All is
working very well with netcat as long as connections are properly
completed.  All connections were properly completed until I started
using a 3com ethernet client bridge and the machine the bridge is
connected to is turned off.  (the whole fin ack connection completion
thing)

So here is my question.  I would like the vocabulary to start searching
for how I can modify netcat to perform a syn/ack or some type of
checking to see if the host at the other end is alive and answering. 
Then if the connection is not alive, I want netcat to close.

I have some spent time looking at the netcat code and watching it in a
debugger and how it loops and flows.  It uses a file descriptor in a
"shoveling loop" for the connection to the host and another for stdin
and stdout.  Then it uses a select call to wait for activity on stdin
and network in before doing any of the work.  An option in netcat is -w
which is the wait time of the timer in the select call.  Optimal would
be to use netcat with a -w and then every time the timer times out
having code added to do a "is the connection alive check" and closing if
no answer is recieved.

Being a little new to coding in c in the unix platform, I am also in
need of a little direction in where to go for documentation on tools. 
This may sound like a loaded question but I feel a little lost when
looking for more information on a function that I see used.  I can grep
and find in the includes directory for functions to see which header it
is declared in but I want just a little bit more description than is
available in the headers some times.  (more than none found in the
headers .. .. examples)  Specifically right now I'm interested in
understanding the following a little better:  FD_ISSET(), FD_SET(),
FD_CLOSE(), connect().  I'm being a little vauge here I know, but I just
want direction and not answers or handholding.

Dirk