I'm trying to implement a Ping program in vb6 which works for both IPv4 & IPv6 addresses. The IPv4 implementation uses IcmpSendEcho which is working fine, but the IPv6 implementation uses Icmp6SendEcho2 and I'm having a lot of difficulty getting it to work.
The function call works fine and it does not error out but the return value is always 0, and GetLastError returns 0 indicating that no errors occurred
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366041(v=vs.85).aspx
The process I follow is as follows:
The definition of Icmp6SendEcho2 is as follows
Private Declare Function Icmp6SendEcho2 Lib "Iphlpapi.dll" _
(ByVal IcmpHandle As Long, _
ByVal EventtoRaise As Long, _
ByVal ApcRoutine As Long, _
ByVal ApcContext As Long, _
ByVal SourceAddressPointer As Long, _
ByVal DestinationAddressPointer As Long, _
ByVal RequestData As String, _
ByVal RequestSize As Long, _
ByVal RequestOptions As Long, _
ReplyBuffer As ICMPV6_ECHO_REPLY, _
ByVal ReplySize As Long, _
ByVal timeOut As Long) As Long
Where ICMPV6_ECHO_REPLY is defined as follows
Private Type ICMPV6_ECHO_REPLY
Address As IPV6_ADDRESS
Status As Long
RoundTripTime As Long
End Type
Private Type IPV6_ADDRESS
sin6_port As Integer
sin6_flowinfo As Long
sin6_addr(1 To 8) As Integer
sin6_scope_id As Long
End Type
The call to Icmp6SendEcho2 is made as follows
lPingResponse = Icmp6SendEcho2(lPortHandle, 0, 0, 0, VarPtr(SourceAddress), VarPtr(DestinationAddress), sMessage, Len(sMessage), 0, Reply, Len(Reply), timeOut)
I used the following link for implementing Ping for IPv4 https://support.microsoft.com/en-us/kb/300197
Any help would be awesome
Nish
The issue was associated with there not being a sufficient buffer to get the response. Changing the response structure to something like this did the trick
Private Type ICMPV6_ECHO_REPLY
Address As IPV6_ADDRESS
Status As Long
RoundTripTime As Long
data(0 To 1023) As Byte
End Type