Project

General

Profile

Feature #277 ยป feature-277.patch

patch for load bpf from file - delta yeh, 05/25/2011 03:18 AM

View differences:

fprintf(stderr, "ERROR: Failed to set bpf filter.\n");
exit(EXIT_FAILURE);
}
}
}
static void SetBpfStringFromFile(char *filename) {
char *bpf_filter = NULL;
uint32_t bpf_len = 0;
struct stat st;
FILE *fp = NULL;
if (stat(filename, &st) != 0) {
SCLogError(SC_ERR_LOGDIR_CMDLINE, "Fail to load bpf from %s", filename);
exit(EXIT_FAILURE);
}
bpf_len=st.st_size + 1;
bpf_filter = SCMalloc(bpf_len);
if (bpf_filter == NULL)
return;
memset(bpf_filter, 0x00, bpf_len);
fp = fopen(filename,"r");
if(fp == NULL) {
SCLogError(SC_ERR_LOGDIR_CMDLINE, "Failt to open bpf file %s", filename);
exit(EXIT_FAILURE);
}
else {
fread(bpf_filter, bpf_filter, 1, fp);
fclose(fp);
}
if(strlen(bpf_filter) > 0) {
if (ConfSet("bpf-filter", bpf_filter, 0) != 1) {
fprintf(stderr, "ERROR: Failed to set bpf filter.\n");
exit(EXIT_FAILURE);
}
}
}
void usage(const char *progname)
{
#ifdef REVISION
printf("%s %s (rev %s)\n", PROG_NAME, PROG_VER, xstr(REVISION));
......
printf("%s %s\n", PROG_NAME, PROG_VER);
#endif
printf("USAGE: %s\n\n", progname);
printf("\t-c <path> : path to configuration file\n");
printf("\t-i <dev or ip> : run in pcap live mode\n");
printf("\t-b <bpf filter file> : bpf filter file\n");
printf("\t-r <path> : run in pcap file/offline mode\n");
#ifdef NFQ
printf("\t-q <qid> : run in inline nfqueue mode\n");
#endif /* NFQ */
#ifdef IPFW
......
};
/* getopt_long stores the option index here. */
int option_index = 0;
char short_opts[] = "c:Dhi:l:q:d:r:us:U:V";
char short_opts[] = "c:Dhi:l:q:d:r:us:U:Vb:";
while ((opt = getopt_long(argc, argv, short_opts, long_opts, &option_index)) != -1) {
switch (opt) {
case 0:
if (strcmp((long_opts[option_index]).name , "pfring") == 0 ||
......
printf("\nThis is %s version %s (rev %s)\n\n", PROG_NAME, PROG_VER, xstr(REVISION));
#else
printf("\nThis is %s version %s\n\n", PROG_NAME, PROG_VER);
#endif
exit(EXIT_SUCCESS);
case 'b':
SetBpfStringFromFile(optarg);
break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
    (1-1/1)