|
If you go to the authors webpage you will find an updated version of CPing much more advanced
|
|
|
|
|
1) You should state that it is necessary to define either CPING_USE_ICMP or CPING_USE_WINSOCK2 or both of them.
You could also note in the article that ICMP version works faster and do not need admin rights as stated in Joerg Tiedemann's message before.
2) I voted 5 inspired by your smtp and pop3 classes, but it was a mistake. This class is rather dirty, has mistakes and usually don't work:
Here is the new version of code (all following changes were made + some other minor changes):
http://register.at.tut.by/sources/ping1.3_ex.zip[^]
a) You should change nPacketSize type from UCHAR to USHORT at least. It can vary from 0 to ~65500.
b) You should change default value of TTL from 10 to 50 at least (100 is better). Lots of users of internet work with hosts as far as 30 hops away or so. Such users will have your ping not working.
Note: each IP host forwarding ICMP echo will reduce TTL by one. Ping packet will be dropped by intermediate host when TTL it become zero.
c) It also could be change TTL and timeout arguments, because more users know and change timeout than TTL.
d) Your IP_HEADER struct is WRONG!
Following two members makes MSVC6 to allocate 4 bytes (even with pack(1) enabled):
unsigned int h_len:4;
unsigned int version:4;
Using bit fields in network structure is not correct. (It depends from compiler and computer system).
Better way is:
<br />
unsigned char VersionAndLen;<br />
<br />
unsigned char h_len() const<br />
{<br />
return VersionAndLen & 0xF;<br />
}<br />
e) You have some duplicate code checking results between ICMP and RAW_IP versions.
f) You lose you error codes while closing connection. Here are new pieces of code:
long le = GetLastError();
closesocket(sockRaw);<br />
SetLastError(le);<br />
long le = GetLastError();
sm_pIcmpCloseHandle(hIP);<br />
SetLastError(le);<br />
g) wrong usage of MIN_ICMP_PACKET_SIZE and MAX_ICMP_PACKET_SIZE. You should separate cases when working with the body of ICMP packet and with body+ICMP_headers (which are exactly 8 bytes).
f) Validation of replies is not complete.
|
|
|
|
|
I am trying to use the ping tool from http://www.naughter.com/ping.html. I downloaded the latest version from here. I compiled the source code and it gives an error saying that "IPExport.h" header file could not be found. I searched the VC++ install directory, but was unable to locate this header file. Can you please help me to locate this file?
Thanks,
Madhavi.
|
|
|
|
|
I'm having problems making it work for a PocketPC with Windows Mobile 5.0.
If I use PingUsingIcmp, IcmpSendEcho(..) returns 87 (invalid parameters)
and if I use PingUsingWinsock, setsockopt(sockRaw, IPPROTO_IP, IP_TTL, ...) returns 10022 (Invalid Argument)
My parameters are as follows:
<br />
m_pIcmpSendEcho(hIP, addr, pBuf, wDataSize, &OptionInfo, pReply, dwReplySize, dwTimeout);<br />
<br />
hIP = 1 (as returned by IcmpCreateFile())<br />
addr = 3238701248 (192.168.10.193)<br />
pBuf = valid buffer<br />
wDataSize=32<br />
OptionInfo.Ttl = 10<br />
OptionInfo.Tos = 0<br />
OptionInfo.Flags = 0<br />
OptionInfo.OptionsSize = 0<br />
OptionInfo.OptionsData = 0<br />
pReply = valid buffer<br />
dwReplySize = 60<br />
dwTimeout = 5000<br />
or
<br />
int nTempTTL = nTTL;<br />
setsockopt(sockRaw, IPPROTO_IP, IP_TTL, reinterpret_cast<char*>(&nTempTTL), sizeof(nTempTTL)<br />
<br />
sockRaw = 5, as returned by WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0, 0)<br />
IPPROTO_IP = 0<br />
IP_TTL = 7, as defined in ws2tcpip.h. I've tried 4 as well, but it doesn't work either.<br />
nTempTTL = 10<br />
Has anybody successfully used the code for Windows Mobile, or does anybody know a good workaround?
P.S.
In both cases the modules ws2.dll and iphlpapi.dll have been loaded.
|
|
|
|
|
Hi, I've had a quick go
- CPING_USE_ICMP : eVC4 reported that 'failed to load ICMP.dll'
or
- for CPING_USE_WINSOCK2 , "CPing::Ping2, Failed to create a raw socket "
I don't think winsock2 is implemented in WinCE though.
Do you know of any fixes for these? I'm unfamiliar with ICMP.dll and don't know if it supported by WinCE.
|
|
|
|
|
If you are using CE, check out the function IcmpSendEcho
|
|
|
|
|
Does this code work with IPv6?
I don't have any machines using IPv6 to test it,
so I'm asking it here.
thx
|
|
|
|
|
No it does not support IPv6, for that check out the function Icmp6SendEcho2
|
|
|
|
|
Hello
I've downloaded the newest version from your website, but the problem is i get the same RTT every time, and the RTT is the same for several ip.
I pinged using icmp, and the ping code has its own thread.
Thanks
|
|
|
|
|
Hi,
I use the CPing class with the function CPing::PingUsingWinsock, but the statements
//Send of the packet
int nWrote = sendto(sockRaw, pICMP, nPacketSize, 0, (sockaddr*)&dest, sizeof(dest));
if (nWrote == SOCKET_ERROR)
{
TRACE(_T("CPing::PingUsingWinsock, sendto failed\n"));
fails. WSAGetLastError() says that Error "WSAEACCES" (10013) occurs.
I logged in as normal Windows user with user-rights
If I use CPing::PingUsingICPM everything works fine.
The function CPing::PingUsingWinsock only works if I logged in at the XP-PC with admin rights.
CPing::PingUsingICPM works with admin and user rights
Has anyone a solution for the problem ?
I have downloaded the newest Version (1.37) for www.naughter.com.
Jörg Tiedemann
|
|
|
|
|
Has same problem. Ping1() does not work with admin privilege.
|
|
|
|
|
Have same problem. Ping1() does not work with admin privilege.
|
|
|
|
|
Have same problem.
"An attempt was made to access a socket in a way forbidden by its access permissions."
Anyone know if there is a way to use raw sockets when running as a limited user in XP SP2?
|
|
|
|
|
I am testing after delte ICMP echo option on windowsXP service pack2.
CPing can't receive Ping Echo.
Teach me..How to receive Ping Echo On windowsXP(with service pack2)
|
|
|
|
|
Just tested the latest version from my web site at www.naughter.com on XP SP2 and I see know problems. I'd suggest you download the latest version and run the code under the debugger to see what is happening. Also have a look at the html documentation which comes with the download
|
|
|
|
|
I am using MFC Socket classes in my project so I'm including afxsock.h header file. When I try to insert the CPing class I must include winsock2.h also, and I get serveral redefinitions. How can I fix these problems?
Thanks.
|
|
|
|
|
The MFC socket classes uses Winsock 1.1 and my raw sockets ping use Winsock 2.0. I'm not really sure how you would go about combining the two in one program (or in fact if you should). I suggest you ditch one or the other. For example use the ICMP version in the ping class. You can exclude the winsock 2 method in my class via a preprocessor directive of "CPING_NO_WINSOCK2". Also try putting winsock2.h before your afxsock.h include.
|
|
|
|
|
How do i get the time it took to go to the server and ping it? The rTTL has been the same everytime I used it.
-Steven
CP Addict
By reading this message you are held fully responsible for any of the mispelln's or grammer, issues, found on, codeproject.com.
For those who were wondering, actual (Linux) Penguins were harmed in creating this message.
|
|
|
|
|
First thing to do is make sure you have the latest version from my web site (www.naughter.com) as this class is now up to v1.32. Also remember on a lan that ping times can be < 10 ms, which is below the nominal timer resolution on Windows 2000 / XP.
|
|
|
|
|
Hi,
After I sorted out the problem of my previous Error 87 (which had been caused by one of the #define new DEBUG_NEW in ping.cpp) I now have the following behavior:
When I try to ping the ftp.download.com I get 11013 back, whereas my ping on the commandline says it can ping it well.
Why is this ? Any idea ?
PS: I'm currently building this as a small example for a PowerBuilder nonvisual extension (PBNI)
|
|
|
|
|
I had a look for this error in the SDK includes, you will see in winerror.h:
// MessageId: WSA_QOS_BAD_OBJECT
//
// MessageText:
//
// Problem with some part of the filterspec or providerspecific buffer in general.
//
#define WSA_QOS_BAD_OBJECT 11013L
Which I'm not sure what that means. I'd suggest you search in the MSDN or Google for references to this. Also I will disable any QOS drivers you have on that machine and see what happens.
|
|
|
|
|
Is there a way to get a better error message ?
I'm looking eg. for what is errorcode 87.
|
|
|
|
|
Just look the error up in the SDK include file "winerror.h". Here it is:
//
// MessageId: ERROR_INVALID_PARAMETER
//
// MessageText:
//
// The parameter is incorrect.
//
#define ERROR_INVALID_PARAMETER 87L // dderror
Also debug through the code to see where the code is failing.
|
|
|
|
|
i want to retrieve the IP address of the machine using VC++
calls
|
|
|
|
|
Not that it is related to my ping class, but just use gethostname followed by gethostbyname
|
|
|
|