#include-once
; Author: Garrett
#Region Vareable & Constants
Global $hICMPDll = 0
Global Const $IP_SUCCESS = 0 ; The status was success.
Global Const $IP_BUF_TOO_SMALL = 11001 ; The reply buffer was too small.
Global Const $IP_DEST_NET_UNREACHABLE = 11002 ; The destination network was unreachable.
Global Const $IP_DEST_HOST_UNREACHABLE = 11003 ; The destination host was unreachable.
Global Const $IP_DEST_PROT_UNREACHABLE = 11004 ; The destination protocol was unreachable.
Global Const $IP_DEST_PORT_UNREACHABLE = 11005 ; The destination port was unreachable.
Global Const $IP_NO_RESOURCES = 11006 ; Insufficient IP resources were available.
Global Const $IP_BAD_OPTION = 11007 ; A bad IP option was specified.
Global Const $IP_HW_ERROR = 11008 ; A hardware error occurred.
Global Const $IP_PACKET_TOO_BIG = 11009 ; The packet was too big.
Global Const $IP_REQ_TIMED_OUT = 11010 ; The request timed out.
Global Const $IP_BAD_REQ = 11011 ; A bad request.
Global Const $IP_BAD_ROUTE = 11012 ; A bad route.
Global Const $IP_TTL_EXPIRED_TRANSIT = 11013 ; The time to live (TTL) expired in transit.
Global Const $IP_TTL_EXPIRED_REASSEM = 11014 ; The time to live expired during fragment reassembly.
Global Const $IP_PARAM_PROBLEM = 11015 ; A parameter problem.
Global Const $IP_SOURCE_QUENCH = 11016 ; Datagrams are arriving too fast to be processed and datagrams may have been discarded.
Global Const $IP_OPTION_TOO_BIG = 11017 ; An IP option was too big.
Global Const $IP_BAD_DESTINATION = 11018 ; A bad destination.
Global Const $IP_GENERAL_FAILURE = 11050 ; A general failure. This error can be returned for some malformed ICMP packets.
Global Const $tag_IP_OPTION_INFORMATION = _
"byte Ttl;" _
&"byte Tos;" _
&"byte FlagsFlagsFlagsFlags;" _
&"byte OptionsSize;" _
&"ptr OptionsData;"
Global Const $tag_ICMP_ECHO_REPLY = _
"ulong Address;" _
&"ulong Status;" _
&"ulong RoundTripTime;" _
&"ushort DataSize;" _
&"ushort Reserved;" _
&"ptr Data;" _
&"struct;"& $tag_IP_OPTION_INFORMATION &"endstruct;" ; IP_OPTION_INFORMATION
#EndRegion Vareable & Constants
#Region Functions
Func _ICMP_CreateFile()
Local Const $INVALID_HANDLE_VALUE = Ptr(0)-1
$a_Ret = DllCall("icmp.dll", "handle", "IcmpCreateFile")
If $a_Ret[0] = $INVALID_HANDLE_VALUE Then ; GetLastError
Return SetError(1, 0, 0)
EndIf
Return SetError(0, 0, $a_Ret[0])
EndFunc ;==>_ICMP_CreateFile
Func _ICMP_CloseHandle($h_Icmp)
$a_Ret = DllCall("icmp.dll", "bool", "IcmpCloseHandle", "handle", $h_Icmp)
If $a_Ret[0] = False Then ; GetLastError
Return SetError(1, 0, 0)
EndIf
Return SetError(0, 0, 1)
EndFunc ;==>_ICMP_CloseHandle
Func _ICMP_SendEcho($h_Icmp, $i_DestIP, $p_ReplyBuff, $p_RequestOpt = 0, $i_Timeout = 3000, $p_RequestData = 0)
$a_Ret = DllCall("icmp.dll", "ulong", "IcmpSendEcho", _
"ptr", $h_Icmp, "uint", $i_DestIP, _
"ptr", DllStructGetPtr($p_RequestData), "dword", DllStructGetSize($p_RequestData), _
"ptr", DllStructGetPtr($p_RequestOpt), _
"ptr", DllStructGetPtr($p_ReplyBuff), "dword", DllStructGetSize($p_ReplyBuff), _
"dword", $i_Timeout)
If Not $a_Ret[0] Then
Return SetError(1, 0, 0)
EndIf
Return SetError(0, 0, $a_Ret[0])
EndFunc ;==> _ICMP_SendEcho
Func _Inet_Addr($s_IP)
Local Const $INADDR_NONE = 0xFFFFFFFF
$a_Ret = DllCall("wsock32.dll", "ulong", "inet_addr", "str", $s_IP)
If $a_Ret[0] = $INADDR_NONE Then
Return SetError(1, 0, 0)
EndIf
Return SetError(0, 0, $a_Ret[0])
EndFunc ;==>_Inet_Addr
Func _Inet_Ntoa($i_IP)
$a_Ret = DllCall("ws2_32.dll", "str", "inet_ntoa", "ulong", $i_IP)
If Not $a_Ret[0] Then
Return SetError(1, 0, 0)
EndIf
Return SetError(0, 0, $a_Ret[0])
EndFunc ;==>_Inet_Ntoa
#EndRegion Functions