Hi,

In an earlier message, we arrived at the conclusion that IcmpSendEcho
and some of its friends are in a static library which we don't have; or
in the iphlpapi DLL which we do.

I've since tried to get the ping application that's on our website to
compile with my poor man's version of MFC. It does, but the next problem
I get is that IcmpSendEcho appears to kill the networking stack on my
PDA.

I've attached stripped example source which can be used to demonstrate
the problem, you can compile it with arm-wince-mingw32ce-g++ .

Clues, anyone ?

        Danny
-- 
Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
#include <wininet.h>
#include <winsock.h>
// #include <windows.h>

#include "ipexport.h"
#include "icmpapi.h"

void LogMe(char *pattern, ...)
{
	va_list ap;
	FILE    *f = fopen("/storage card/devel/log.txt", "a");

	va_start(ap, pattern);
	vfprintf(f, pattern, ap);
	va_end(ap);
	fclose(f);
}

void ping_fun()
{	
	char szchrIPAddr[30];
	HANDLE hIcmp;
	char* lpToSend = "Ping information";
	char str[250];

	BYTE bIn[1024];
	int rc;
	in_addr ipFromAddress;
	PICMP_ECHO_REPLY lpEchoReply;
	DWORD dwToPing;	
	WCHAR szMsg[260];

	LogMe("Yow %d\n", __LINE__);
	dwToPing = inet_addr("172.17.1.2");
	LogMe("Yow %d\n", __LINE__);
	if(dwToPing == -1)
	{
	LogMe("Yow %d\n", __LINE__);
		HOSTENT* lphostent = gethostbyname(szchrIPAddr);
	LogMe("Yow %d\n", __LINE__);
		if(lphostent == NULL)
		{		
	LogMe("Yow %d\n", __LINE__);
			MessageBox(NULL, TEXT("Invaliad Address."), TEXT("ERROR"), MB_OK);
			return;
		}		
	LogMe("Yow %d\n", __LINE__);
		in_addr address;
		memcpy(&address, lphostent->h_addr_list[0], sizeof(address));
		dwToPing = address.S_un.S_addr;
	}
	LogMe("Yow %d\n", __LINE__);
	hIcmp = IcmpCreateFile();
	LogMe("Yow %d\n", __LINE__);

	if(hIcmp == INVALID_HANDLE_VALUE)
	{
	LogMe("Yow %d\n", __LINE__);

		MessageBox(NULL, TEXT("Can't intialize Ping."), TEXT("ERROR"), MB_OK);
		return;
	}
	

	LogMe("Yow %d\n", __LINE__);
	rc  = IcmpSendEcho(hIcmp, dwToPing, lpToSend, strlen(lpToSend), 
				NULL, bIn, sizeof(bIn), 0);
	LogMe("Yow %d\n", __LINE__);

	if(rc == 0) {		
		sprintf((char *)str, "Ping %s Timeout!", szchrIPAddr);
		//dialog->AppendStatus(str);			
	} else
	{
		lpEchoReply = (PICMP_ECHO_REPLY)bIn;
		for(int i = 0; i < rc; i++)
		{
			memcpy(&ipFromAddress, &lpEchoReply->Address, sizeof(in_addr));			
			sprintf((char *)str, "Reply from: %s (%ld ms)", 
				inet_ntoa(ipFromAddress), lpEchoReply->RoundTripTime);						
			int	iLen = MultiByteToWideChar(CP_ACP, NULL, (char *)str, strlen((char *)str), szMsg, 250);
			szMsg[iLen] = '\0';				
//			dialog->AppendStatus(str);	

			lpEchoReply++;	// move to next reply
		}
	}

	IcmpCloseHandle(hIcmp);

}

int APIENTRY WinMain(HINSTANCE inst, HINSTANCE pi, LPWSTR cmd, int show)
{
	WSADATA	d;

	LogMe("Yow %d\n", __LINE__);
	WSAStartup(MAKEWORD(2,2), &d);
	LogMe("Yow %d\n", __LINE__);
	ping_fun();
	return 0;
}
-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to