네트워크 및 보안/pcap 라이브러리

[pcap 라이브러리] 9. 필터식 BSF 문법 확인 (pcap_compile, pcap_compile_nopcap)

언제나휴일 2016. 4. 29. 22:05
반응형

필터식 BSF 문법 확인


pc_fake.c

//pc_fake.c

#include <pcap.h>

 

int main(int argc,char **argv){

  char errbuf[PCAP_ERRBUF_SIZE];   

  pcap_t *device = pcap_open_dead(0,1024);

  if(device == 0){ printf("fail open_dead...%s\n",errbuf); return 0; }

 

  struct bpf_program fcode;

 

  if(pcap_compile(device,&fcode,argv[1], 0,0)<0){

    printf("fail compile. check syntax\n");

    return 3;  

  }//if

  printf("success compile. %s syntax is available! \n",argv[1]);

}

 

 

아답터없이 필터식 확인


int pcap_compile_nopcap(int csize, int linktype, struct bpf_program *program,

               const char *expression, int optimize, bpf_u_int32 mask);

pc_compile_nopcap.c


//pc_compile_nopcap.c

#include <pcap.h>

 

 

int main(int argc,char **argv){

  char errbuf[PCAP_ERRBUF_SIZE];   

/*  pcap_t *device = pcap_open_dead(0,1024);

  if(device == 0){ printf("fail open_dead...%s\n",errbuf); return 0; }

*/

  struct bpf_program fcode;

  pcap_compile_nopcap(1024,0,&fcode,argv[1],0,0);

 

 /*

  if(pcap_compile(device,&fcode,argv[1], 0,0)<0){

    printf("fail compile. check syntax\n");

    return 3;  

  }//if*/

  printf("success compile. %s syntax is available! \n",argv[1]);

}

 

반응형