Beispiel #1
0
int hold_child(pid_t child, command_options *options) {

    while(1) {
        if(options->ptrace_on) {
            run_trace(child);
        }

        if(watch_signals(child) != 0) break;
    }

    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[]) {

	int i;
	int opt;
	char *filterstring=NULL;
	struct sigaction sigact;
	int count = -1;

	libtrace_filter_t *filter = NULL;/*trace_bpf_setfilter(filterstring); */

	while (1) {
		int option_index;
		struct option long_options[] = {
			{ "count", 		1, 0, 'c' },
			{ "ecn",		0, 0, 'C' },
			{ "direction", 		0, 0, 'd' },
			{ "drops",		0, 0, 'D' },
			{ "error",		0, 0, 'e' },
			{ "flow", 		0, 0, 'F' },
			{ "filter",		1, 0, 'f' },
			{ "help",		0, 0, 'H' },
			{ "misc",		0, 0, 'm' },
			{ "nlp",		0, 0, 'n' },
			{ "tcpoptions",		0, 0, 'O' },
			{ "synoptions",		0, 0, 'o' },
			{ "protocol", 		0, 0, 'P' },
			{ "port",		0, 0, 'p' },
			{ "tcpsegment", 	0, 0, 's' },
			{ "tos",		0, 0, 'T' },
			{ "ttl", 		0, 0, 't' },
			{ NULL, 		0, 0, 0 }
		};
		opt = getopt_long(argc, argv, "Df:HemFPpTtOondCsc:", 
				long_options, &option_index);
		if (opt == -1)
			break;
		
		switch (opt) {
			case 'c':
				count = atoi(optarg);
				break;
			case 'C':
				reports_required |= REPORT_TYPE_ECN;
				break;
			case 'd':
				reports_required |= REPORT_TYPE_DIR;
				break;
			case 'D':
				reports_required |= REPORT_TYPE_DROPS;
				break;
			case 'e':
				reports_required |= REPORT_TYPE_ERROR;
				break;
			case 'F':
				reports_required |= REPORT_TYPE_FLOW;
				break;
			case 'f':
				filterstring = optarg;
				break;
			case 'H':
				usage(argv[0]);
				break;
			case 'm':
				reports_required |= REPORT_TYPE_MISC;
				break;
			case 'n':
				reports_required |= REPORT_TYPE_NLP;
				break;
			case 'O':
				reports_required |= REPORT_TYPE_TCPOPT;
				break;
			case 'o':
				reports_required |= REPORT_TYPE_SYNOPT;
				break;
			case 'P':
				reports_required |= REPORT_TYPE_PROTO;
				break;
			case 'p':
				reports_required |= REPORT_TYPE_PORT;
				break;
			case 's':
				reports_required |= REPORT_TYPE_TCPSEG;
				break;
			case 'T':
				reports_required |= REPORT_TYPE_TOS;
				break;
			case 't':
				reports_required |= REPORT_TYPE_TTL;
				break;
			default:
				usage(argv[0]);
		}
	}

	/* Default to all reports, instead of no reports at all.  It's annoying
	 * waiting for 10 minutes for a trace to process then discover you 
	 * forgot to ask for any reports!
	 */
	if (reports_required == 0) {
		reports_required = ~0;

		/* Except we might want to not do the flow report, because 
		 * that can be rather resource-intensive */
		reports_required &= ~REPORT_TYPE_FLOW;
	}


	if (filterstring) {
		filter = trace_create_filter(filterstring);
	}

	sigact.sa_handler = cleanup_signal;
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = SA_RESTART;

	sigaction(SIGINT, &sigact, NULL);
	sigaction(SIGTERM, &sigact, NULL);
		
	
	for(i=optind;i<argc;++i) {
		/* This is handy for knowing how far through the traceset
		 * we are - printing to stderr because we use stdout for
		 * genuine output at the moment */
		fprintf(stderr, "Reading from trace: %s\n", argv[i]);
		run_trace(argv[i],filter, count);
	}

	if (reports_required & REPORT_TYPE_MISC)
		misc_report();
	if (reports_required & REPORT_TYPE_ERROR)
		error_report();
	if (reports_required & REPORT_TYPE_FLOW)
		flow_report();
	if (reports_required & REPORT_TYPE_TOS)
		tos_report();
	if (reports_required & REPORT_TYPE_PROTO)
		protocol_report();
	if (reports_required & REPORT_TYPE_PORT)
		port_report();
	if (reports_required & REPORT_TYPE_TTL)
		ttl_report();	
	if (reports_required & REPORT_TYPE_TCPOPT)
		tcpopt_report();
	if (reports_required & REPORT_TYPE_SYNOPT)
		synopt_report();
	if (reports_required & REPORT_TYPE_NLP)
		nlp_report();
	if (reports_required & REPORT_TYPE_DIR)
		dir_report();
	if (reports_required & REPORT_TYPE_ECN)
		ecn_report();
	if (reports_required & REPORT_TYPE_TCPSEG)
		tcpseg_report();
	if (reports_required & REPORT_TYPE_DROPS)
		drops_report();
	return 0;
}
Beispiel #3
0
int main(int argc, char *argv[]) {

    int i;
    struct sigaction sigact;

    while(1) {
        int option_index;
        struct option long_options[] = {
            { "filter",	   1, 0, 'f' },
            { "libtrace-help", 0, 0, 'H' },
            { NULL, 	   0, 0, 0   },
        };

        int c=getopt_long(argc, argv, "f:H",
                          long_options, &option_index);

        if (c==-1)
            break;

        switch (c) {
        case 'f':
            ++filter_count;
            filters=realloc(filters,filter_count*sizeof(struct filter_t));
            filters[filter_count-1].expr=strdup(optarg);
            filters[filter_count-1].filter=trace_create_filter(optarg);
            filters[filter_count-1].count=0;
            filters[filter_count-1].bytes=0;
            break;
        case 'H':
            trace_help();
            exit(1);
            break;
        default:
            fprintf(stderr,"Unknown option: %c\n",c);
            usage(argv[0]);
            return 1;
        }
    }

    if(optind > argc - 1)
    {
        usage(argv[0]);
        exit(-1);
    }

    sigact.sa_handler = cleanup_signal;
    sigemptyset(&sigact.sa_mask);
    sigact.sa_flags = SA_RESTART;

    sigaction(SIGINT, &sigact, NULL);
    sigaction(SIGTERM, &sigact, NULL);

    for(i=optind; i<argc; ++i) {
        run_trace(argv[i]);
    }
    if (optind+1<argc) {
        fprintf(stderr, "Grand total:\n");
        fprintf(stderr,
                "%30s:\t%12"PRIu64"\t%12" PRIu64 "\n",
                "Total",totcount,totbytes);
    }


    return 0;
}