ICMP Issue
-
I'm adding IPv6 functionality to an application that has been designed to monitor the hosts by sending periodical ICMP packets (pings). According to MSDN and the checkv4 utility, the addrinfo structure should be used, which works well when calling Icmp6SendEcho2[^] , however the problems arise when calling the IcmpSendEcho2 [^], because the fifth argument, the DestinationAddress is IPAddr struct type. So the real question is: Are there any fuctions that will convert an addrinfo structure to an IPAddr or is there another way of doing this? (Using a bunch of if/else statements to check for IPv4/6 is not an option)
-
I'm adding IPv6 functionality to an application that has been designed to monitor the hosts by sending periodical ICMP packets (pings). According to MSDN and the checkv4 utility, the addrinfo structure should be used, which works well when calling Icmp6SendEcho2[^] , however the problems arise when calling the IcmpSendEcho2 [^], because the fifth argument, the DestinationAddress is IPAddr struct type. So the real question is: Are there any fuctions that will convert an addrinfo structure to an IPAddr or is there another way of doing this? (Using a bunch of if/else statements to check for IPv4/6 is not an option)
Declare a new address type like this:
typedef struct _SOCKADDR_IPv4v6
{
union
{
sockaddr_in addrv4;
sockaddr_in6 addrv6;
};} SOCKADDR_IPv4v6, *PSOCKADDR_IPv4v6;
SOCKADDR_IPv4v6 addr;
Icmp6SendEcho2( ..., &addr.addrv6, ... ); // if addr is IPv6
IcmpSendEcho2( ..., addr.addrv4.sin_addr, ... ); // if addr is IPv4Don't try it, just do it! ;-)