ping()

The ping() call sends a ping to the remote host to determine if the host is responding.

Syntax

#include <ftpapi.h>

int ping(addr, len)
unsigned long addr;
int len;

Parameters

addr

len

Description

The ping() call sends a ping to the host with ICMP Echo Request. The ping() call is useful to determine whether the host is alive before attempting FTP transfers, because time-out on regular connections is more than a minute. The ping() call returns within 3 seconds, at most, if the host is not responding.

Return Values

If the return value is positive, the return value is the number of milliseconds it took for the echo to return. If the return value is negative, it contains an error code.

The following are ping() call return codes and their corresponding descriptions:

Return Code

PINGREPLY PINGSOCKET PINGPROTO PINGSEND PINGRECV

Examples

#include <stdio.h>#include <netdb.h>
#include <ftpapi.h>

struct hostent *hp;     /* Pointer to host info */

main(int argc, char *argv[], char *envp[])
{
   int i;
   unsigned long addr;

   if (argc!=2) {
     printf("Usage: p <host>\n");
     exit(1);
   }

   hp = gethostbyname(argv[1]);

if (hp) {
        memcpy( (char *)&addr, hp->h_addr, hp->h_length);
        i = ping(addr,256);
        printf("ping reply in %d milliseconds\n",i);
} else {
        printf("unknown host\n");
        exit(2);
       }
       ftplogoff(); /* close all connections */
}


[Back: Keep_File_Date()]
[Next: Resource ReSerVation Protocol API]