Advertisement
haazee

l1.c

Aug 15th, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <regex.h>
  4.  
  5. int main(int argc, char *argv[]){
  6.     int n1,n2,rc;
  7.     FILE *fp;
  8.     char buff[1000];
  9.     regex_t preg;
  10.     regmatch_t mat;
  11.  
  12.  
  13.     n1=0;
  14.     n2=0;
  15.  
  16.     regcomp(&preg, "^.{11}\\s\\d\\d:\\d\\d:\\d\\d\\s\\S+\\s\\w+\\.\\w+\\s\\w+:\\s+ACCEPT|REJECT|DROP\\s+.*$", REG_EXTENDED);
  17.  
  18.     fp=fopen("kern.log","r");
  19.    
  20.     while(fgets(buff,sizeof(buff),fp) != NULL){
  21.         rc=regexec(&preg, buff, 1, &mat, 0);
  22.         if(rc>0){
  23.                 n1++;
  24.         } else {
  25.                 n2++;
  26.         }
  27.     }
  28.     printf("count: %u %u\n",n1,n2);
  29.  
  30.     fclose(fp);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement