I'm writing a program at the moment that needs to know if another
host is up before sending data. The approach I'm using currently is to try
and open a tcp socket on the remote machine that I know isn't been
listened on. Here is the sample code:
void alarm_handler(int num)
int main(int argc, char *argv)
struct sockaddr_in peer;
printf("connecting to %s:%d\n",inet_ntoa(peer.sin_addr),ntohs(peer.sin_port));
if(sigsetjmp(jmp_env,1) == 0)
printf("returned from connect with ret_val %d\n",ret_val);
Now - network programming isn't my strong point, so I was wondering if any
of ye lot have any idea if this can be made better (i.e. lower latency or
bandwidth). As it stands, there are only two packets sent, one in each
direction - to me that seems pretty much optimal. BTW the other machine is
a sun box which I have no control over if that makes any difference.
"My mom had Windows at work and it hurt her eyes real bad"
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!