Subj : Re: test a computer presence on the network in C To : Fabrice Bentejac LM2S From : Remove the letters in all caps\ Date : Wed Oct 06 2004 07:50 am Fabrice Bentejac LM2S wrote: >Hello, >I'd like to test, inside a C program, whether a computer is present on the >network (equivalent to a "ping" command. >What could I use to do that? > >Thanks in advance. > >F.B. > > int test(char *computer ){ int status; char buffer[BUFLEN+12]; char *command = "ping -c 4 "; if ( strlen( computer ) + strlen( command ) >= BUFLEN ) { fprintf (stderr, "The computer name is 'way too long"); exit (2); }; strcpy ( buffer, command); /* copy the command to the buffer, first part in building the command string */ strcat ( buffer, computer ); /* copy the computer name, which finishes the command string */ strcat ( buffer, ">/dev/null" ); fprintf ( stderr, "The command is %s\n", buffer ); status = system( buffer ); return ( status ); } main(){ printf ( "%s is %s\n", COMPUTER1, test(COMPUTER1) ? "down" : "up" ); printf ( "%s is %s\n", COMPUTER2, test(COMPUTER2) ? "down" : "up" ); } .