Función PING en Harbour / PING function in Harbour

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
Posts: 143
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB
Location: PERU
Has thanked: 1 time
Been thanked: 4 times

Función PING en Harbour / PING function in Harbour

Post by edufloriv » Mon Jan 29, 2018 2:29 pm

Saludos amigos,

En el área de almacén tengo el problema que apagan el router y cuando inician su módulo les lanza un error porque evidentemente no hay conexión con el servidor. Quería consultarles si existe en Harbour una función similar a "Ping" del DOS, para verificar la disponibilidad de la red. Sé que puedo hacer un .batch y ejecutarlo con EXECUTE FILE pero quise consultarles si conocen alguna función en Harbour que haga lo mismo.

Agradeciendo su ayuda, reciban mis cordiales saludos.


Greetings, friends

In the warehouse area I have the problem that they turn off the router and when they start their module it throws an error because obviously there is no connection to the server. I wanted to ask if there is a function in Harbor similar to "Ping" of DOS, to verify the availability of the network. I know I can do a .batch and execute it with EXECUTE FILE but I wanted to ask if you know any function in Harbour that does the same.

Thank you for your help, receive my cordial greeting.

Eduardo Flores Rivas


Posts: 420
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 125 times
Been thanked: 331 times

Post by edk » Mon Jan 29, 2018 3:14 pm

User avatar
Posts: 1101
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 28 times
Been thanked: 64 times

Post by andyglezl » Mon Jan 29, 2018 3:31 pm

Quizá algo de aquí pueda servir...
Maybe something here can serve ... ... tem#p32282
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
Posts: 1048
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 182 times
Been thanked: 85 times

Post by bpd2000 » Tue Jan 30, 2018 4:43 am

Ping command in Harbour is here
Attached working example, change xurl := "" to xurl := etc.

Code: Select all

Check Internet connectivity through PING command and it is reliable
From bpd2000
Expert help from KDJ

#include ""

   Local xerrdescription , xurl := ""
   xerrdescription := HB_PING(xurl)
   Do Case
      Case xerrdescription = 0
       MSGINFO("Ping to " + xurl + " Succesful", "Internet Connection Available")
      Case xerrdescription = 11001
       MSGINFO("The reply buffer was too small.")
      Case xerrdescription = 11002
       MSGINFO("The destination network was unreachable.")
      Case xerrdescription = 11003
       MSGINFO("The destination host was unreachable.")
      Case xerrdescription = 11004
       MSGINFO("The destination protocol was unreachable.")
      Case xerrdescription = 11005
       MSGINFO("The destination port was unreachable.")
      Case xerrdescription = 11006
       MSGINFO("Insufficient IP resources were available.")
      Case xerrdescription = 11007
       MSGINFO("A bad IP option was specified.")
      Case xerrdescription = 11008
       MSGINFO("A hardware error occurred.")
      Case xerrdescription = 11009
       MSGINFO("The packet was too big.")
      Case xerrdescription = 11010
       MSGINFO("The request timed out." + hb_osnewline() +"Internet Connection Not Available")    
      Case xerrdescription = 11011
       MSGINFO("A bad request.")
      Case xerrdescription = 11012
       MSGINFO("A bad route.")
      Case xerrdescription = 11013
       MSGINFO("The time to live (TTL) expired in transit.")
      Case xerrdescription = 11014
       MSGINFO("The time to live expired during fragment reassembly.")
      Case xerrdescription = 11015
       MSGINFO("A parameter problem.")
      Case xerrdescription = 11016
       MSGINFO("Datagrams are arriving too fast to be processed" + hb_osnewline() + ;
       " and datagrams may have been discarded.")
      Case xerrdescription = 11017
       MSGINFO("An IP option was too big.")
      Case xerrdescription = 11018
       MSGINFO("A bad destination.")
      Case xerrdescription = 11050
        MSGINFO("A general failure" + hb_osnewline() + ;
          "This error can be returned for some malformed ICMP packets.")
        msginfo("Internet Connection Not Available")

#pragma BEGINDUMP 

#include <hbapi.h> 
#include <winsock2.h> 
#include <iphlpapi.h> 
#include <icmpapi.h> 

int hb_Ping( const char * cp ) 
    HANDLE hIcmpFile; 
    unsigned long ipaddr = INADDR_NONE;     // corrected by KDJ
    DWORD dwRetVal; 
    char SendData[32] = "Data Buffer"; 
    LPVOID ReplyBuffer; 
    DWORD ReplySize; 

    if( isalpha( cp[0] ) )      //host address is a name 
       WSADATA wsaData; 
       int     iResult; 

       iResult = WSAStartup( MAKEWORD(2, 2), &wsaData ); 

       if( iResult == 0 ) 
          struct hostent *remoteHost = gethostbyname( cp ); 

          if( remoteHost != NULL ) 
             ipaddr = *(unsigned long *) remoteHost->h_addr_list[0]; 

       ipaddr = inet_addr( cp ); 

    if (ipaddr == INADDR_NONE) 
        return 1; 
    hIcmpFile = IcmpCreateFile(); 
    if (hIcmpFile == INVALID_HANDLE_VALUE) 
        return 2; 

    ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); 
    ReplyBuffer = (VOID*) malloc(ReplySize); 
    if (ReplyBuffer == NULL) 
        return 3; 
    dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData), 
        NULL, ReplyBuffer, ReplySize, 1000); 



    if (dwRetVal == 0) 
        return GetLastError(); 
    return 0; 


   hb_retni( hb_Ping( hb_parc( 1 ) ) ); 

#pragma ENDDUMP 
Convert Dream into Reality through HMG

Post Reply