Working Ping...

M

Mobileboy36

Hello group,

My function BasePing doesn't work any more on mobile 2005.
I get an unsuspected error (no more information is displayed) on the line
calling "LOCALFREE".
On pocket pc 2003 i still have "normal" behavior.
It 's the second time I post this because I don't succeed to resolve the
problem.
Maybe some of you are capable to solve the (little) problem. Or does anyone
have a working ping
function based on IcmpSendEcho for Mobile 2005???
A working version would be very useful for me and the other compact
framework programmers.
I hope anyone can say what I have to change exactly.


best regards,
Mobile boy


<System.Runtime.InteropServices.DllImport("coredll") _
Private Shared Function LocalAlloc(ByVal Flags As Integer, ByVal
size As Integer) As System.IntPtr
End Function

' extern public static IntPtr LocalFree(IntPtr pMem);
<System.Runtime.InteropServices.DllImport("coredll") _
Private Shared Function LocalFree(ByVal pMem As System.IntPtr) As
System.IntPtr
End Function

<System.Runtime.InteropServices.DllImport("iphlpapi") _
Private Shared Function IcmpSendEcho( _
ByVal IcmpHandle As System.IntPtr, _
ByVal DestinationAddress As Integer, _
ByVal RequestData As Byte(), _
ByVal RequestSize As Short, _
ByVal RequestOptions As System.IntPtr, _
ByVal ReplyBuffer As Byte(), _
ByVal ReplySize As Integer, _
ByVal Timeout As Integer) As Integer
' returntype zou UInt32 moeten zijn, maar ja geen operators
ondersteunt in Vb.net
End Function


Private Function BasePing(ByVal IpAddress As System.Net.IPAddress, ByVal
TimeOut As Integer, ByVal SendBufferSizeInBytes As Integer) As Integer
' returnwaarden:
'
' -1: Failed to ping, reason other then Request Timed out
' 0: Request Timed out
' 0: Request Time

Dim Result As Integer = 0
'Dim RequestData As Byte() =
System.Text.Encoding.ASCII.GetBytes(New String("\0", 64))
Dim RequestData As Byte() =
System.Text.Encoding.ASCII.GetBytes(New String(Chr(0), 64))
Dim Reply As ICMP_ECHO_REPLY
Dim pData As System.IntPtr
Dim h As System.IntPtr
Dim intIpaddr As Integer
Dim ret As Integer
Dim dwErr As Integer = 0

'RequestData = System.Text.Encoding.ASCII.GetBytes(New
String("\0", 64))
RequestData = System.Text.Encoding.ASCII.GetBytes(New
String(Chr(0), 64))


'Allocate ICMP_ECHO_REPLY structure
Reply = New ICMP_ECHO_REPLY(255)
Reply.DataSize = 255
pData = LocalAlloc(LMEM_ZEROINIT, Reply.DataSize)
Reply.Data = pData
h = IcmpCreateFile()
intIpaddr = MyIpConvertor(IpAddress)
ret = IcmpSendEcho(h, intIpaddr, RequestData,
System.Convert.ToInt16(RequestData.Length), IntPtr.Zero, Reply._Data,
Reply._Data.Length, TimeOut)

If (ret = 0) Then
dwErr = GetLastError()
If (dwErr < 11010) Then 'If error is other than timeout -
display a message
Result = -1
'"Failed to ping. Error code: " + dwErr.ToString())
End If
Else
If (dwErr < 11010) Then ' Then
'String.Format("RTT: {0}, Data Size: {1} TTL: {2}",
Reply.RoundTripTime, Reply.DataSize, Reply.Ttl
Result = Reply.RoundTripTime
Else
'Request timed out
Result = 0
End If
End If
IcmpCloseHandle(h)
LocalFree(Reply.Data)

Return Result
End Function
 
S

Simon Hart [MVP]

I use the Ping class from the OpenNETCF library which works on all PPC 2003,
WM5 and WM6, yet again the OpenNETCF libraries save you a lot of work and
grief.
 
T

Tal

Simon Hart said:
I use the Ping class from the OpenNETCF library which works on all PPC 2003,
WM5 and WM6, yet again the OpenNETCF libraries save you a lot of work and
grief.
 
T

Tal

Simon Hart said:
I use the Ping class from the OpenNETCF library which works on all PPC 2003,
WM5 and WM6, yet again the OpenNETCF libraries save you a lot of work and
grief.


Hi Simon,
I am also using OPENNETCF ping class. I am working on my uni project but
dont have access to actual PDA.
Ping class seems to work fine with IPv4 addresses
when I test it in emulator by pinging 127.0.0.1 it works fine but when I try
its alternative in IPV6 i.e ::1 it throws exception.
Also, is there anyway I can get a list of IP Addresses that replied with
echo messages.


Your help will be appreciated
 
P

Paul G. Tobey [eMVP]

Yes, it's an IPv4 ping. You'll have to write your own for IPv6.

I'm not sure I understand this question, "Also, is there anyway I can get a
list of IP Addresses that replied with echo messages."? What do you mean?
What "list"?

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top