#pragma option w32c
#pragma option lst

#define _WINBASE_ TRUE
#define _WINSOCK_ TRUE
#define _ADVAPI_ TRUE

#includepath "c:\c--\open_lib"

#include "windows.h--"
#include "ipexport.h--"
#include "write.h--"
#include "ip2mac.h--"
#include "pings.h--"

#define BASEIP 0x01A8C0	// base ip=192.168.1.00
#define NUMIPSEGM 7

byte copyright="\n\t(C) Mishel Sheker. KNPP. "__DATE__"\n";
dword handl;
dword adrThread[NUMIPSEGM];

void WriteInfo(dword buf)
{
dword butesRW;
	IF(handl!=-1)WriteFile(handl,buf,lstrlen(buf),#butesRW,0);
	WriteStr(buf);
}

void main()
{
WSADATA WSAData;
int i,id;
	if(WSAStartup(0x101,#WSAData)==0){
		handl=CreateFileA("ping.txt",GENERIC_WRITE,
				FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
		FOR(i=0;i<NUMIPSEGM;i++){	//init class and create threads
			EDI=adrThread[i]=GlobalAlloc(GMEM_FIXED,sizeof(PINGS));
			EDI.PINGS.InitPing(i<<16+BASEIP);
			CreateThread(NULL,0,#EDI.PINGS.Ping,EDI,0,#id);
			CloseHandle(EAX);
		}
		for(;;){	//wait to end pings
			Sleep(0);
			id=0;
			FOR(i=0;i<NUMIPSEGM;i++){
				EDI=adrThread[i];
				IF(!EDI.PINGS.scaning)id++;
			}
			IF(id==NUMIPSEGM)BREAK;
		}
		FOR(i=0;i<NUMIPSEGM;i++){	//end pings
			EDI=adrThread[i];
			EDI.PINGS.EndPing();
			GlobalFree(EDI);
		}
		WriteInfo(#copyright);
		IF(handl!=-1)CloseHandle(handl);
	}
	WSACleanup();
}
