Exemple #1
0
Fichier : ion.c Projet : b/ION
int	startIonMemTrace(int size)
{
	return psm_start_trace(_ionwm(NULL), size, NULL);
}
Exemple #2
0
static int	run_file2dgr(char *remoteHostName, char *fileName)
{
	int		cyclesLeft;
	char		ownHostName[MAXHOSTNAMELEN + 1];
	unsigned int	ownIpAddress;
	unsigned int	remoteIpAddress;
	unsigned short	remotePortNbr = TEST_PORT_NBR;
	PsmMgtOutcome	outcome;
	DgrRC		rc;
	FILE		*inputFile;
	char		line[256];
	int		lineLen;
	struct timeval	startTime;
	unsigned long	bytesSent;

	cyclesLeft = cyclesRequested;
	getNameOfHost(ownHostName, sizeof ownHostName);
	ownIpAddress = getInternetAddress(ownHostName);
	remoteIpAddress = getInternetAddress(remoteHostName);
	sm_ipc_init();
	wmPtr = malloc(wmSize);
	if (wmPtr == NULL
	|| psm_manage(wmPtr, wmSize, "dgr", &dgrwm, &outcome) < 0
	|| outcome == Refused)
	{
		putErrmsg("Can't acquire DGR working memory.", NULL);
		writeErrmsgMemos();
		return 0;
	}
#if 0
psm_start_trace(dgrwm, 10000000, NULL);
#endif

	memmgr_add("dgr", allocFromDgrMemory, releaseToDgrMemory, dgrAtoP,
			dgrPtoA);
	if (dgr_open(ownIpAddress, 2, 0, ownIpAddress, "dgr", &dgr, &rc) < 0
	|| rc != DgrOpened)
	{
		putErrmsg("Can't open dgr service.", NULL);
		writeErrmsgMemos();
		return 0;
	}

	inputFile = fopen(fileName, "r");
	if (inputFile == NULL)
	{
		putSysErrmsg("Can't open input file", fileName);
		writeErrmsgMemos();
		return 0;
	}

	eofLineLen = strlen(eofLine);
	getCurrentTime(&startTime);
	bytesSent = 0;

	/*	Copy text lines from file to SDR.			*/

	while (cyclesLeft > 0)
	{
		if (fgets(line, 256, inputFile) == NULL)
		{
			if (feof(inputFile))
			{
				if (dgr_send(dgr, remotePortNbr,
					remoteIpAddress, DGR_NOTE_FAILED,
					eofLine, eofLineLen, &rc) < 0)
				{
					putErrmsg("dgr_send failed.", NULL);
					writeErrmsgMemos();
					fclose(inputFile);
					return 0;
				}

				bytesSent += eofLineLen;
				fclose(inputFile);
				cyclesLeft--;
				if (cyclesLeft == 0)
				{
					inputFile = NULL;
					break;
				}

				inputFile = fopen(fileName, "r");
				if (inputFile == NULL)
				{
					putSysErrmsg("Can't reopen input file",
							NULL);
					writeErrmsgMemos();
					return 0;
				}

				continue;
			}
			else
			{
				putSysErrmsg("Can't read from input file",
						NULL);
				writeErrmsgMemos();
				fclose(inputFile);
				return 0;
			}
		}

		lineLen = strlen(line);
		if (dgr_send(dgr, remotePortNbr, remoteIpAddress,
				DGR_NOTE_FAILED, line, lineLen, &rc) < 0)
		{
			putErrmsg("dgr_send failed", NULL);
			writeErrmsgMemos();
			fclose(inputFile);
			return 0;
		}

		bytesSent += lineLen;
	}

	report(&startTime, bytesSent);
	writeMemo("[i] file2dgr waiting 10 sec for retransmission to stop.");
	snooze(10);
	dgr_close(dgr);
#if 0
psm_print_trace(dgrwm, 0);
psm_stop_trace(dgrwm);
#endif
	if (inputFile)
	{
		fclose(inputFile);
	}

	return 0;
}