From: Sardaukary on
Hello,

I'm trying to write a very simple program to ping ip addresses.

IcmpSendEcho2 seems to be what I need

http://windowssdk.msdn.microsoft.com/en-us/library/aa366051.aspx

Unfortunately the MSDN website is next to useless as none of the
examples are complete leaving you to trial and error the necessary libs
and header files.

c:\program files\microsoft platform sdk\include\icmpapi.h(175) : error
C2061: syntax error : identifier 'IPAddr'
c:\program files\microsoft platform sdk\include\icmpapi.h(264) : error
C2061: syntax error : identifier 'IPAddr'
c:\program files\microsoft platform sdk\include\icmpapi.h(288) : error
C2061: syntax error : identifier 'PIP_OPTION_INFORMATION'

is what I get when I try to compile this

#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <IcmpAPI.h>

int main(){


// Declare and initialize variables
char *SendData = "Data Buffer";
LPVOID ReplyBuffer;
ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) +
sizeof(SendData));

if ((dwRetVal = IcmpSendEcho2(hIcmpFile,
NULL,
NULL,
NULL,
inet_addr("123.456.789.0"),
SendData,
sizeof(SendData),
NULL,
ReplyBuffer,
8*sizeof(SendData) + sizeof(ICMP_ECHO_REPLY),
1000)) != 0) {
printf("\tReceived %ld messages.\n", dwRetVal);
printf("\tMessage: %s\n", ReplyBuffer);
}
else {
printf("\tCall to IcmpSendEcho2() failed.\n");
printf("\tError: %ld\n", GetLastError());
}
system("pause");

}

Any help would be most appreciated. I'm using Visual Studio 2005
express (I have MingW setup but thought it was asking for trouble
trying to use gcc with microsoft libraries) and have installed the
Windows SDK.

From: Michael K. O'Neill on
IPAddr and IP_OPTION_INFORMATION are both found in the IP Helper API.

Try also including Iphlpapi.h and linking to Iphlpapi.lib.

Mike

<Sardaukary(a)gmail.com> wrote in message
news:1160222287.970380.101940(a)c28g2000cwb.googlegroups.com...
> Hello,
>
> I'm trying to write a very simple program to ping ip addresses.
>
> IcmpSendEcho2 seems to be what I need
>
> http://windowssdk.msdn.microsoft.com/en-us/library/aa366051.aspx
>
> Unfortunately the MSDN website is next to useless as none of the
> examples are complete leaving you to trial and error the necessary libs
> and header files.
>
> c:\program files\microsoft platform sdk\include\icmpapi.h(175) : error
> C2061: syntax error : identifier 'IPAddr'
> c:\program files\microsoft platform sdk\include\icmpapi.h(264) : error
> C2061: syntax error : identifier 'IPAddr'
> c:\program files\microsoft platform sdk\include\icmpapi.h(288) : error
> C2061: syntax error : identifier 'PIP_OPTION_INFORMATION'
>
> is what I get when I try to compile this
>
> #include <winsock2.h>
> #include <windows.h>
> #include <iostream>
> #include <IcmpAPI.h>
>
> int main(){
>
>
> // Declare and initialize variables
> char *SendData = "Data Buffer";
> LPVOID ReplyBuffer;
> ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) +
> sizeof(SendData));
>
> if ((dwRetVal = IcmpSendEcho2(hIcmpFile,
> NULL,
> NULL,
> NULL,
> inet_addr("123.456.789.0"),
> SendData,
> sizeof(SendData),
> NULL,
> ReplyBuffer,
> 8*sizeof(SendData) + sizeof(ICMP_ECHO_REPLY),
> 1000)) != 0) {
> printf("\tReceived %ld messages.\n", dwRetVal);
> printf("\tMessage: %s\n", ReplyBuffer);
> }
> else {
> printf("\tCall to IcmpSendEcho2() failed.\n");
> printf("\tError: %ld\n", GetLastError());
> }
> system("pause");
>
> }
>
> Any help would be most appreciated. I'm using Visual Studio 2005
> express (I have MingW setup but thought it was asking for trouble
> trying to use gcc with microsoft libraries) and have installed the
> Windows SDK.
>