Stephen Shirley wrote:
> Mornin' all,
> Here's the problem. I had a linux box (A), and a sun box (B). They
> are both connected to a 100mb switched private lan. They are the
> only boxen on this network. I have complete control over A, but none
> over B. I need to be able to write a program to run on A that will
> detect as fast as possible if B is up or down. Calling ping or any
> other external programs is out of the question - too much overhead.
> This might have to be done many times a second. My initial idea was
> to open a tcp connection to a port i know is closed on B, thereby
> getting a REJECT, and confirming it's up. This solution takes on
> average 509 usecs to say yay, and times out after 500 msecs
> (configurable) to say nay.
>> Now it's been suggested that I try some facny tcp half-connect
> modes, or maybe even arp. However, networks aren't my speciality. I
> was wondering if anyone had any suggestions/comments.
I've done TCP syn stealth scanning like you suggest, but
it won't help in your case I think as you're just going
to duplicate what the kernel code would do anyway. The
only advantage of explicitly doing syn stealth scanning
is that if you are scanning/monitoring ports that are
possibly connected, then it's slower (because the server
then has to SYN_ACK/fork()/log()/...).
So a timed connect to a known unconnected port seems like
the best way to do it. Note the 509 usecs is probably
mostly due to the latency introduced by the network cables
and switch. It may be beneficial to directly connect A & B
with a crossover cable.
How do you do the timed connect?
The best method I think is:
fcntl(nonblocking)
connect()
select(read,timeout)?
Padraig.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!