|
-
November 30th, 2004, 05:02 AM
#1
ping a server in vc.net
I wrote code in vc++ 6.0 to ping a server which works well but the same doesnt work in vc.net .
i tried with the following lib files
#pragma comment(linker,ws2_32)
ws2_32.lib
#pragma comment( linker, "/defaultlib:ws2_32.lib")
and i aslo included the winsock2.h
Could any one suggest me a solution
-
November 30th, 2004, 06:31 AM
#2
Re: ping a server in vc.net
Well...what does not work?
-
November 30th, 2004, 07:47 AM
#3
Re: ping a server in vc.net
the application is giving linking errors
-
November 30th, 2004, 07:50 AM
#4
Re: ping a server in vc.net
Well...what linker errors?
-
November 30th, 2004, 07:59 AM
#5
Re: ping a server in vc.net
error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function _WinMain@16
error LNK2019: unresolved external symbol __imp__gethostbyaddr@12 referenced in function _WinMain@16
error LNK2019: unresolved external symbol __imp__gethostbyname@4 referenced in function _WinMain@16
error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _WinMain@16
these are linking errors i am getting when i execute the same code in vc.net,
-
November 30th, 2004, 09:59 AM
#6
Re: ping a server in vc.net
Code:
#pragma comment (lib, "ws2_32")
-
December 1st, 2004, 12:53 AM
#7
Re: ping a server in vc.net
i tried #pragma comment (lib, "ws2_32") but still i am getting the same errors
-
December 1st, 2004, 02:18 AM
#8
Re: same problem with winsock32.dll
hi,
i had the same linking problem with winsock32.dll. the code compiled fine, but i couldn't link to the mentioned dll -- unresolved externals on dll functions. couldn't find a solution
notyetguru,
(MSVC++ 6.0)
-
December 1st, 2004, 03:13 AM
#9
Re: ping a server in vc.net
Well...that is interesting...can you post a compilable sample program which recreates the error?
-
December 1st, 2004, 03:57 AM
#10
Re: ping a server in vc.net
Oiriginally posted by Andreas Masur
Well...that is interesting...can you post a compilable sample program which recreates the error?
Well, I don't have the source code of the program here (at my job). I tried to develop the client/server winsock based program some years ago when i was learning visual c++, it was for learning purposes only, and after getting the unresolved external errors i gave up after a while. i don't know if i still have the
source code on my home computer. however, the questions remain, since then
i wasn't confronted with internet socket programming again.
notyetguru,
(MSVC++ 6.0)
-
December 1st, 2004, 04:18 AM
#11
Re: ping a server in vc.net
the core part of the code is
#include "stdafx.h"
#include "Pingnet.h"
#include "PingnetDlg.h"
#include"winsock2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
void abc(char *p)
{
FILE *fp=fopen("TraceNet.TXT","a+");
fprintf(fp,"%s\n",p);
fclose(fp);
}
struct o
{
unsigned char Ttl;
unsigned char a[7];
};
struct
{
DWORD Address;
unsigned long Status,RoundTripTime;
unsigned char a[8];
struct o Options;
} E;
HANDLE hIP;WSADATA wsa;HANDLE hIcmp;DWORD *dwIPAddr;struct hostent *phostent;
DWORD d;char aa[100];struct o I;char bb[100];int z;
HANDLE ( WINAPI *pIcmpCreateFile )( VOID );
BOOL ( WINAPI *pIcmpCloseHandle )( HANDLE );
DWORD (WINAPI *pIcmpSendEcho) (HANDLE,DWORD,LPVOID,WORD, LPVOID,LPVOID,DWORD,DWORD);
void CPingnetDlg::OnBnClickedOk()
{
hIcmp = LoadLibrary( "ICMP.DLL" );
WSAStartup( 0x0101, &wsa );
pIcmpCreateFile = (HANDLE (WINAPI *)(void))
GetProcAddress((HMODULE)hIcmp,"IcmpCreateFile");
pIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
GetProcAddress((HMODULE)hIcmp,"IcmpCloseHandle");
pIcmpSendEcho = (DWORD (WINAPI *)
(HANDLE,DWORD,LPVOID,WORD, LPVOID,LPVOID,DWORD,DWORD))
GetProcAddress((HMODULE)hIcmp,"IcmpSendEcho");
hIP = pIcmpCreateFile();
for ( z = 1; z<= 20 ; z++)
{
I.Ttl=(unsigned char)z;
// phostent = gethostbyname( "66.28.63.63");
phostent = gethostbyname( "64.246.52.100");
// phostent = gethostbyname( "66.98.128.62");
dwIPAddr = (DWORD *)( *phostent->h_addr_list );
pIcmpSendEcho(hIP,*dwIPAddr,0,0,&I,&E,sizeof(E),8000 );
d=E.Address;
phostent = gethostbyaddr((char *)&d,4,PF_INET);
if ( phostent != 0)
strcpy(aa,phostent->h_name) ;
else
strcpy(aa,"no host name");
wsprintf(bb," RTT: %dms, TTL: %d", E.RoundTripTime, E.Options.Ttl );
strcat(aa,bb);
abc(aa);
if ( E.Options.Ttl )
{
AfxMessageBox("Pinging");
break;
}
}
pIcmpCloseHandle( hIP );
FreeLibrary((HMODULE)hIcmp);
WSACleanup();
// TODO: Add your control notification handler code here
//OnOK();
}
this code worked fine in vc++ 6.0 but not vc.net
-
December 1st, 2004, 04:34 AM
#12
Re: ping a server in vc.net
give it a try with
Code:
#pragma comment(lib, "winsock32.dll")
just curious
notyetguru,
(MSVC++ 6.0)
-
December 1st, 2004, 04:46 AM
#13
Re: ping a server in vc.net
still it is not working with #pragma comment(lib, "winsock32.dll")
-
December 2nd, 2004, 06:17 AM
#14
Re: ping a server in vc.net
is there anyway to solve my problem
-
December 7th, 2004, 02:05 AM
#15
Re: ping a server in vc.net
can anyone bring me out of this labyrinth
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|