Example #1
0
int MyQtFile::myfClose()
{
    return lfclose(fdQfile);
}
Example #2
0
File: pktzip.c Project: chemag/pktd
/*
 * main
 *
 *	Main procedure. Sets default values, parses arguments from command line, 
 *	and calls uncompress or compress depending on the file linktype
 *
 */
int main (int argc, char **argv)
{
	FILE *fin;
	lFILE *lfout;
	struct pcap_file_header filehdr;
	int swapped;
	co_t co;
	char filter[PROT_MAX_INDIVIDUAL_FILTER];

	/* get the file names */
	finname[0] = '\0';
	foutname[0] = '\0';
	parse_args (argc, argv);


	/* open input file */
	if ((finname[0] == '-' && finname[1] == '\0') || (finname[0] == '\0')) {
		fin = stdin;
	} else {
		fin = fopen (finname, "r");
		if (fin == NULL) {
			fprintf (stderr, "Error: cannot open file %s\n", finname);
			exit (1);
		}
	}

	/* read the input header to know whether it's compressed or not */
	if (pktd_fread_header (fin, &filehdr, &swapped, &co, filter) < 0) {
		fprintf (stderr, "Error: file %s has wrong format\n", finname);
		exit (1);
	}


	if (filehdr.version_minor == 5) {
		/* pcap extended header */
		printf ("Extended IP header contains mask: 0x%02x\n", co.ip_mask); /* XXX */
		printf ("Extended TCP header contains mask: 0x%04x\n", co.tcp_mask); /* XXX */
		printf ("Extended UDP header contains mask: 0x%02x\n", co.udp_mask); /* XXX */
		printf ("Extended header contains offset: %i\n", co.rm_offset); /* XXX */
		printf ("Extended header contains filter: %s\n", filter); /* XXX */
	}


	/* open output file */
	if ((foutname[0] == '-' && foutname[1] == '\0') || (foutname[0] == '\0')) {
		lfout = lfdopen (STDOUT_FILENO, 8192);
	} else {
		lfout = lfopen (foutname, 8192);
		if (lfout == NULL) {
			fprintf (stderr, "Error: cannot open file %s\n", foutname);
			fclose (fin);
			exit (1);
		}
	}


	/* check if the file is compressed or not */
	if (filehdr.linktype == DLT_COMPRESSED) {
		uncompress_file (fin, lfout, &co);
	} else {
		compress_file (fin, lfout, &filehdr, swapped);
	}

	fclose (fin);
	lfclose (lfout);
	exit (0);
}