Article View: borland.public.cppbuilder.internet.socket
Article #1795console ping example
From: DeKayA
Date: Sun, 29 Oct 2006 02:30
Date: Sun, 29 Oct 2006 02:30
82 lines
3546 bytes
3546 bytes
I don't know if this is the correct place for this but since it uses
sockets and ports I made a guess.
This is reputed to be a PING.c example.
it came from
http://www.vijaymukhi.com/vmis/wsockexp.htm
I downloaded it directly from the web and attempted to create a
console app. I think it is quite old code.
When I compile it it gives me several errors but all are so similar
that I think the resolution for one will apply to many.
So here goes.
The error messages are
indicated by a -> at the begriming of the line
No doubt very basic for experienced programmers but...
//------------------------------------------------------------------
[34] E2034 Cannot convert 'void*" to HINSTANCE__*'
[34] E2343 Type mismatch in parameter "hModule" in call to '__stdcall
GetProcAddress(HINSTANCE__*,const char *]"
[34] E2034 Cannot convert *int(__stdcall*)()' to void * (__stdcall *
)()'
//------------------------------------------------------------------
#include <windows.h>
struct o
{
unsigned char Ttl,Tos,Flags,OptionsSize,*OptionsData;
};
struct
{
DWORD Address;
unsigned long Status,RoundTripTime;
unsigned short DataSize,Reserved;
void *Data;
struct o Options;
} E;
HANDLE hIP;WSADATA wsa;HANDLE hIcmp;DWORD *dwIPAddr;struct hostent
*phostent;
DWORD d;char aa[100];struct o I;
HANDLE ( WINAPI *pIcmpCreateFile )( VOID );
BOOL ( WINAPI *pIcmpCloseHandle )( HANDLE );
DWORD (WINAPI *pIcmpSendEcho)(HANDLE,DWORD,LPVOID,WORD,LPVOID,
LPVOID,DWORD,DWORD);
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrev,
LPSTR lpCmd,int nShow )
{
hIcmp = LoadLibrary( "ICMP.DLL" );
WSAStartup( 0x0101, &wsa );
phostent = gethostbyname( "www.microsoft.com");
dwIPAddr = (DWORD *)( *phostent->h_addr_list );
-> pIcmpCreateFile=GetProcAddress( hIcmp,"IcmpCreateFile");
-> pIcmpCloseHandle=GetProcAddress( hIcmp,"IcmpCloseHandle");
-> pIcmpSendEcho =GetProcAddress( hIcmp,"IcmpSendEcho" );
hIP = pIcmpCreateFile();
I.Ttl=6;
pIcmpSendEcho(hIP,*dwIPAddr,0,0,&I,&E,sizeof(E),8000 );
d=E.Address;
phostent = gethostbyaddr((char *)&d,4,PF_INET);
sprintf(aa,"gethostbyaddr %p",phostent );
MessageBox(0,aa,aa,0);
if ( phostent != 0 ) MessageBox(0,phostent->h_name,"hi",0);
wsprintf(aa,"RTT: %dms,TTL:%d", E.RoundTripTime, E.Options.Ttl );
MessageBox(0,aa,"hi",0);
pIcmpCloseHandle( hIP );
FreeLibrary( hIcmp );
WSACleanup();
}
//-----------------------------------------------------------------
Technical Details
Message-ID:
<45440dc2.34466740@forums.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!feeder.news-service.com!194.25.134.62.MISMATCH!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,31ea45a742d03588,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: DeKayA@bellsouth.net Newsgroups: borland.public.cppbuilder.internet.socket Subject: console ping example Date: Sun, 29 Oct 2006 02:30:13 GMT Message-ID: <45440dc2.34466740@forums.borland.com> X-Newsreader: Forte Agent 1.5/32.452 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 72.153.143.202 X-Trace: newsgroups.borland.com 1162089084 72.153.143.202 (28 Oct 2006 19:31:24 -0700) Lines: 82 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!feeder.news-service.com!194.25.134.62.MISMATCH!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail