Hello,
How can I check if a SMTP-server is existing?
I'd like to test it with for instance uit.telenet.be.
Thanks a lot for any help.
FUNCTION MAIN()
? HB_PING( "uit.telenet.be" )
RETURN NIL
#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;
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];
WSACleanup();
}
}
else
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)
{
IcmpCloseHandle(hIcmpFile);
return 3;
}
dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
NULL, ReplyBuffer, ReplySize, 1000);
free(ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
if (dwRetVal == 0)
return 4;
return 0;
}
HB_FUNC( HB_PING )
{
hb_retni( hb_Ping( hb_parc( 1 ) ) );
}
#pragma ENDDUMP
#include "FiveWin.ch"
FUNCTION MAIN()
LOCAL cTestPing
// Direct of Machine(computer).
// cTestPing := ( "http://speedtest.copel.net/" ) // Correct
// ShellExecute(GetActiveWindow(),"open",'"'+cTestPing+'"') // correct
// cTestPing := ( "uit.telenet.be" ) // ERROR return 0
cTestPing := ( "http://duits.telenet.be/" ) // return 4, correct?
? HB_PING( cTestPing )
RETURN NIL
#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;
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];
WSACleanup();
}
}
else
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)
{
IcmpCloseHandle(hIcmpFile);
return 3;
}
dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
NULL, ReplyBuffer, ReplySize, 1000);
free(ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
if (dwRetVal == 0)
return 4;
return 0;
}
HB_FUNC( HB_PING )
{
hb_retni( hb_Ping( hb_parc( 1 ) ) );
}
#pragma ENDDUMP
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 19 guests