Using IcpmSendEcho API function with PB 3.94

Share your advanced PureBasic knowledge/code with the community.
Marc
User
User
Posts: 28
Joined: Mon Jun 16, 2003 9:02 pm
Location: Paris - Villemer
Contact:

Using IcpmSendEcho API function with PB 3.94

Post by Marc »

Code updated For 5.20+

Following my post in bug section please find how to use the IcmpSendEcho function with PB 3.94 according with MSDN specification about the ReplyBuffer.
See: http://msdn.microsoft.com/library/defau ... decho.asp.

I hope this is a good help and info...

Code: Select all



EchoMessage.s = "MVPing make a Ping Test"
ResultSize.l = SizeOf(ICMP_ECHO_REPLY) + Len(EchoMessage)
*Result = AllocateMemory(ResultSize) 
*Echo.ICMP_ECHO_REPLY = *Result

If OpenConsole() 
  ConsoleTitle("MVPing")
  Repeat
    ConsoleColor(15,0)
    Print("Adresse IP: ")
    ConsoleColor(10,0)
    sIPAddress.s = Input() 
    PrintN("")
    
    If Len(sIPAddress ) > 0 
      hFile.l = IcmpCreateFile_() 
      IPAddress.l=MakeIPAddress(Val(StringField(sIPAddress,1,".")),Val(StringField(sIPAddress,2,".")),Val(StringField(sIPAddress,3,".")),Val(StringField(sIPAddress+".",4,".")))  
      ConsoleColor(14,0)
      For Boucle.l = 1 To 4 
        lngResult.l = IcmpSendEcho_(hFile, IPAddress, EchoMessage, Len(EchoMessage), 0, *Result, ResultSize, 500) 
        PrintN("Ping " + sIPAddress + " Octets: " + Str(*Echo\DataSize) + " Temps: " + Str(*Echo\RoundTripTime) + " ms TTL:" + StrU(*Echo\Options\Ttl,#PB_Byte))
        Delay(500)
      Next 
      IcmpCloseHandle_(hFile)
    EndIf 
  Until sIPAddress= ""
  FreeMemory(*Result)
EndIf
End

Marc from PARIS - MVCOM Library
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Bon soir Marc,

for any IP address I get the following lines back:

Code: Select all

<IP or domain name> Octets: 0  Temps 1507348 ms TTL=77
The zero-bytes value may be correct, as the lines were printed rather fast. The ping times must be wrong, perhaps an overflow somewhere?


//EDIT: ok, the above error report is only valid for domain names, not when using IP addresses directly. With IP addresses it works perfectly well. Apparently, domain names don't get resolved into IP addresses.

salut
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply