|
|
WSA Error 10022 comes out
when run in windows XP SP2
may i know what is the cause and how to solve it
thanks
|
|
|
|
|
hi! are the sources files of the ping are updated without the bug??? please let me know!!! and ansere!! cu surf.
|
|
|
|
|
Hello,
I have a short question.
I open this ping-dialog as a non-modal dialog and the ping request is send (for example 10 retries). I can close the dialog, but I can't do anything in the parent dialog, because the ping is also running in background. After a few seconds, when the ping is over all is ok.
How can I stop the ping-thread when the non-modal dialog should be close???
Thanxx
Jessica
|
|
|
|
|
I tried to do a broadcast ping in my application but it gives me a runtime error. By the way, I am working in Windows 2000 server and use winSock2.h to deal with sockets. I feel that you will give me part of your time to answer me. I will ask you another favore, if you know any good E_books to learn the network programming.
thank you. . . .
|
|
|
|
|
HI
when I try to run WinPing under Windows XP envirment
I get SOCKET_ERROR in the following code:
rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
something wrong with the system or any ideas?
How can I solve the problem?
thanks
|
|
|
|
|
you must initlaize socket before creating socket
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
|
|
|
|
|
maybe you forgot to initialize the socket envirment with afxsockinit function.
|
|
|
|
|
I ran this application twice and the ping response
of the first ping appears on the second application.
|
|
|
|
|
Hi, please see my message at:
http://www.codeproject.com/internet/winping.asp?df=100&forumid=905&select=445021#xx445021xx
the next to your message.
Regards,
Hanney
|
|
|
|
|
Scene - 1: Use the executable to ping a dead host (ie. 129.133.156.100), 50 retries, start to ping, it should always receive a timeout message.Well, start a command window now, use windows ping to ping an active host (ie. 127.0.0.1), see what happend in WinPing window -- it got a reply, why?
Scene - 2: Use the executable to ping a dead host (ie. 129.133.156.100), 50 retries, start to ping, it should always receive a timeout message.Well, start another WinPing window now and ping an active host (ie. 127.0.0.1), see what happend in WinPing window
-- it got a reply, why?
Regards,
Hanney Wang
|
|
|
|
|
WinPing have this bug because it don't test if a icmp packet received is an answer for it.
In other words, Windows give to WinPing all icmp packets are received(included answer pings for other winping instances), and in the RecvEchoReply functions, you must verify what packets are yours. One method is used to solve this, is save in the id field of icmp header the process id and compare the value of this in all icmp packets received.
|
|
|
|
|
I'm aware of these bugs, I'll get round to updating this article soon.
|
|
|
|
|
Thank you! But so sorry for the late reply!
I also realized this problem from Microsoft code sample, so, I
had found an other way to solve this problem - using MS ICMP APIs. Here is my code:
#define PING_WINSOCK_VERSION 0x0101
#define PING_REQ_DATASIZE 64 // Echo Request Data size
#define PING_ERROR_SUCCESS 0
#define PING_ERROR_TIMEOUT 1
#define PING_ERROR_SOCKET 2
typedef struct tagIPINFO
{
unsigned char Ttl; // Time To Live
unsigned char Tos; // Type Of Service
unsigned char IPFlags; // IP flags
unsigned char OptSize; // Size of options data
unsigned char far * Options; // Options data buffer
}IPINFO, *PIPINFO;
typedef struct tagICMPECHO
{
unsigned long Source; // Source address
unsigned long Status; // IP status
unsigned long RTTime; // Round trip time in milliseconds
unsigned short DataSize; // Reply data size
unsigned short Reserved; // Unknown
void far * pData; // Reply data buffer
IPINFO ipInfo; // Reply options
}ICMPECHO, * PICMPECHO;
// Ping results
typedef struct tagPINGINFO
{
char cHostName[32];
char cIpAddress[20];
char cErrorMessage[256];
unsigned int blTimouted;
short nSendBytes;
short nReplyBytes;
unsigned long nReplyTime;
unsigned char nReplyTTL;
}PINGINFO, *PPINGINFO;
__declspec(dllexport) unsigned int _cdecl PingHost( void far* lpPingInfo )
{
PPINGINFO pPingInfo = (PPINGINFO)lpPingInfo;
if(pPingInfo == NULL)return( FALSE );
HANDLE (WINAPI *pIcmpCreateFile)(VOID);
BOOL (WINAPI *pIcmpCloseHandle)(HANDLE);
DWORD (WINAPI *pIcmpSendEcho)
(HANDLE,DWORD,LPVOID,WORD,PIPINFO,LPVOID,DWORD,DWORD);
HANDLE hndlIcmp; // LoadLibrary() handle to ICMP.DLL
WSADATA wsaData; // WSADATA
struct in_addr iaDest; // Internet address structure
LPHOSTENT pHost; // Pointer to host entry structure
DWORD *dwAddress; // IP Address
HANDLE hndlFile; // Handle for IcmpCreateFile()
// Dynamically load the ICMP.DLL
hndlIcmp = LoadLibrary("ICMP.DLL");
if (hndlIcmp == NULL)
{
sprintf(pPingInfo->cErrorMessage, "Could not load ICMP.DLL!");
return( PING_ERROR_SOCKET );
}
// Retrieve ICMP function pointers
pIcmpCreateFile = (HANDLE (WINAPI *)(void))
GetProcAddress((HMODULE)hndlIcmp,"IcmpCreateFile");
pIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))
GetProcAddress((HMODULE)hndlIcmp,"IcmpCloseHandle");
pIcmpSendEcho = (DWORD (WINAPI *)
(HANDLE,DWORD,LPVOID,WORD,PIPINFO,LPVOID,DWORD,DWORD))
GetProcAddress((HMODULE)hndlIcmp,"IcmpSendEcho");
// Check all the function pointers
if (pIcmpCreateFile == NULL ||
pIcmpCloseHandle == NULL ||
pIcmpSendEcho == NULL)
{
sprintf(pPingInfo->cErrorMessage, "Error loading ICMP.DLL functions!");
FreeLibrary((HMODULE)hndlIcmp);
return( PING_ERROR_SOCKET );
}
// Init WinSock
if (WSAStartup(PING_WINSOCK_VERSION, &wsaData))
{
sprintf(pPingInfo->cErrorMessage, "Winsock could not be initialized!");
WSACleanup();
return( PING_ERROR_SOCKET );
}
// Check WinSock version
if (0x0101 != wsaData.wVersion)
{
sprintf(pPingInfo->cErrorMessage, "No WinSock version 1.1 support found!");
WSACleanup();
FreeLibrary((HMODULE)hndlIcmp);
return( PING_ERROR_SOCKET );
}
// Resovling the Host
iaDest.s_addr = inet_addr(pPingInfo->cHostName);
if (iaDest.s_addr == INADDR_NONE)
pHost = gethostbyname(pPingInfo->cHostName);
else
pHost = gethostbyaddr((const char *)&iaDest,
sizeof(struct in_addr), AF_INET);
if (pHost == NULL)
{
sprintf(pPingInfo->cErrorMessage, "Unable resolve host %s!", pPingInfo->cHostName);
FreeLibrary((HMODULE)hndlIcmp);
WSACleanup();
return( PING_ERROR_SOCKET );
}
// Copy the IP address
dwAddress = (DWORD *)(*pHost->h_addr_list);
// Get an ICMP echo request handle
hndlFile = pIcmpCreateFile();
if(hndlFile < 0)
{
sprintf(pPingInfo->cErrorMessage, "Unable get ICMP handle!");
FreeLibrary((HMODULE)hndlIcmp);
WSACleanup();
return( PING_ERROR_SOCKET );
}
// Start to Ping
unsigned char request_data[PING_REQ_DATASIZE];
unsigned char reBuff[sizeof(ICMPECHO)+200];
IPINFO ipInfo; // IP Options structure
ICMPECHO *icmpEcho = NULL; // ICMP Echo reply buffer
memset(reBuff, 0, sizeof(ICMPECHO)+200);
memset(request_data, 0, sizeof(request_data));
memset(&ipInfo, 0, sizeof(ipInfo));
ipInfo.Ttl = 255;
ipInfo.Options = request_data;
pIcmpSendEcho(
hndlFile, // Handle from IcmpCreateFile()
*dwAddress, // Destination IP address
request_data, // Pointer to buffer to send
sizeof(request_data), // Size of buffer in bytes
&ipInfo, // Request options
reBuff, // Reply buffer
sizeof(reBuff),
1000); // Time to wait in milliseconds
icmpEcho = (ICMPECHO *) reBuff;
// Get the results
iaDest.s_addr = icmpEcho->Source;
sprintf(pPingInfo->cIpAddress, "%s", inet_ntoa(iaDest));
if (icmpEcho->Status)
{
sprintf(pPingInfo->cErrorMessage, "%d - Request timed out.", icmpEcho->Status);
pPingInfo->blTimouted = TRUE;
pPingInfo->nReplyBytes = pPingInfo->nReplyTTL = 0;
pPingInfo->nReplyTime = 0;
}
else
{
sprintf(pPingInfo->cErrorMessage, "No Error!");
pPingInfo->blTimouted = FALSE;
pPingInfo->nReplyBytes = icmpEcho->DataSize;
pPingInfo->nReplyTTL = icmpEcho->ipInfo.Ttl;
pPingInfo->nReplyTime = icmpEcho->RTTime;
}
// Close the echo request file handle
pIcmpCloseHandle(hndlFile);
FreeLibrary((HMODULE)hndlIcmp);
WSACleanup();
return pPingInfo->blTimouted ? PING_ERROR_TIMEOUT : PING_ERROR_SUCCESS ;
}
Regards,
Hanney
|
|
|
|
|
Hi,Sonu,
I'm trying to find your message in the forums, but I failed. So I reply your message here, sorry for the late reply.
To answer your question, one point I need to clarify is the codes I post can run 2 instances in one App, but for the code of Norm Almond, I encountered an error while 1 of 2 host is NOT active, the code will drop into a dead loop in "recvfrom" (RecvEchoReply).
I made a small changes for WinPing so that it can detect which packet it should response, the key is "ID" of ICMPHDR structure, while you send ICMP request, this member data should be filled in your own process(or Thread) ID.
1) in CPing::SendEchoRequest, replace the "nID++" with your own thread ID
echoReq.icmpHdr.ID = (USHORT)GetCurrentThreadId();
2) in "DWORD CPing::RecvEchoReply" detect your own packet:
for(;;)
{
// Receive the echo reply
nRet = recvfrom(s, // socket
(LPSTR)&echoReply, // buffer
sizeof(ECHOREPLY), // size of buffer
0, // flags
(LPSOCKADDR)lpsaFrom, // From address
&nAddrLen); // pointer to address len
if( echoReply.echoRequest.icmpHdr.ID == (USHORT)GetCurrentThreadId() ) break;
// If NOT equal, it's someone else packet
}
Hope it can answer your question, any question, please send me email.
Best Regards,
Hanney Wang
|
|
|
|
|
thanks for the code. It worked very well. I have send you an another email. Please let me know about that.
thanks
da sonu
|
|
|
|
|
It seems not to be a good idea to put recvfrom in an infinite loop.
My solution:
(before calling WaitForEchoReply in CPing::Ping)
m_dwStart = GetTickCount();
m_dwStart is a private member of CPing.
(in the for(;;) loop)
if (GetTickCount() - m_dwStart > 1000)<br />
{<br />
break;<br />
}
|
|
|
|
|
I am beginner programmer from Polish. I began work over my newprogramme and I hit on little trouble. I must place data (HTML code) in indicator WebBrowser2. Does not go me here for loading of file HTML from disc with method Navigte( 2,...). I want to know how must I implement a code to transfer HTML code from board eg CStringArray to WebBrowser2. If You can help, please write back.
|
|
|
|
|
Hi
I am system Administrator.we are supplying internet to customers.how can i control the bandwidth supply to users ,of varying subcribtion.
Now every customer is getting the full bandwidth regardless of his subcribtion.Please help in this matter.
can we control the bandwidth speed thru server programming like ASP or XML.
with regards
balaje.R.P
|
|
|
|
|
Not the right place to ask such a question.
|
|
|
|
|
Please help me in finding the ip of the local host.
-C
|
|
|
|
|
127.0.0.1
|
|
|
|
|
TRY:
void DiscoverLocalIP()
{
TCHAR szHostName[1024];
//first get the local host's name
int res = gethostname(szHostName , 1024);
if (res == 0)
{
//then get the host's information by its name
HOSTENT *phost = gethostbyname(szHostName);
if (phost)
{
//phost->h_addr_list records the host's IP array
for( int i = 0; phost->h_addr_list[i] != 0; i++ )
{
//here we get each of the host's IP which is in network byte order
ULONG ulIP = *(ULONG *)phost->h_addr_list[i];
}
}
}
}
Don't forget to initialize WinSock library before call these WinSock APIs.
BTW,127.0.0.1 is only the roll_back address.
Cheers
|
|
|
|
|
loopback..
|
|
|
|
|
Dear Sir
How to get the ping result shown with current time and continuously get result at a time interval like 15 minutes?
Shown like this(15 minutes interval):
Reply from:123.456.12.34; bytes=32 time=1111ms TTL=123,at 12:00am,05/19/2002
Reply from:123.456.12.34; bytes=32 time=1222ms TTL=123,at 12:15am,05/19/2002
and so on.
Thanks a lot!!!!!
XYZ
|
|
|
|
|