#include #include #include #include #include #include #include #include #include #include "iptable.h" #include "types.h" int processfile(char *); /* CMD-Line Options parssing -I print Inside <-> Inside traffic to stdout */ int main(int argc, char **argv) { DIR *mydir; struct dirent *dp; struct stat sb; if (argc != 2) { printf("%s: parse_flowfile \n",argv[0]); exit(1); } init_iptable(); if (0!=stat(*(argv+1),&sb)) { perror("Stat"); exit(1); } /* Just one Flowfile */ if (S_IFREG & sb.st_mode) { printf("File\n"); processfile(*(argv+1)); /* a directory */ } else if (S_IFDIR & sb.st_mode) { chdir(*(argv+1)); mydir=opendir("."); if (!mydir) { perror("Opendir"); exit(1); } while ((dp = readdir(mydir)) != NULL) { /* if(dp->d_type == DT_REG) */ if (1) { if (0==strncmp("flow.",dp->d_name,5)) { fprintf(stderr,"Flowfile:%s\n",dp->d_name); fflush(stdout); processfile(dp->d_name); } else { /* Unknown File */ fprintf(stderr,"Uknkown Filetype:%s\n",dp->d_name); } } } closedir(mydir); } dump_iptable(); return 0; } int processfile(char *filename){ int fd; struct flowfileheader header; struct saveflow flow; int n; int r; fd=open(filename,O_RDONLY); if (fd<0) { perror("open flowfile"); exit(1); } n=read(fd,&header,sizeof(struct flowfileheader)) ; if (n!=sizeof(struct flowfileheader )) { perror("Short read header"); exit(1); } if (!( ( header.magic[0]=='N' ) && ( header.magic[1]=='P' ) && ( header.magic[2]=='F' ) && ( header.magic[3]=='F' ) )) { printf("No NPFF File\n"); exit(1); } while( ( r = read(fd, &flow, sizeof( struct saveflow ) ) ) ) { addflow(&flow, ntohl(header.starttime) ); } close(fd); return 0; }