2013-08-07 5 views
0

PCAP 파일 목록을 한 번에 열고 PCAP 파일 목록을 하나의 출력 파일로 출력하는 경험이 있습니까? 예를 들어, 1.pcap, 2.pcap 및 3.pcap을 가지고 있고, 1.pcap, 2.pcap 및 3.pcap에 대한 처리를하고 싶습니다. 그 결과를 하나의 출력 pcap 파일 (output.pcap). 다음은 현재 내 코드입니다.PCAP 파일 목록 읽기

static pcap_t *input = NULL; 
input = pcap_open_offline(packet_path, errbuf); 
if (input == NULL){exit(0);} 
pktMatch = pcap_dump_open(input, "-"); 
/*Do some processing, eg to find an IP*/ 
compareIP=true; 
if (compareIP){ 
    pcap_dump(pktMatch, &pktHeader, pktData); 
    continue; 
} 

위의 코드는 단일 입력 pcap 파일을 읽는 데 사용할 수 있습니다. 질문 : 단일 pcap_open_offline() 메소드에서 파일 목록 (1.pcap, 2.pcap, 3.pcap)을 열 수 있도록이 코드를 수정하려면 무엇을 변경해야합니까? 어떤 전문가가 조언하고 싶습니까? 감사합니다

답변

1

여기에 몇 가지 의사 코드가 있습니다. 실제 코드로 바꾸는 것은 당신의 직업입니다.

for (all files) { 
    new pcap = pcap_open_offline(the file, errbuf); 
    if (new pcap == NULL) { 
     fprintf(stderr, "Opening \"%s\" failed: %s\n", the file, errbuf); 
     exit(1); 
    } 
    add new pcap to the list of pcaps to read; 
} 
mark all files as not having a packet yet; 
for (;;) { 
    for (all open files) { 
     if (the file doesn't have a packet yet) 
      read a packet from the file and make it that file's current packet; 
    } 
    packet time = nothing; 
    for (all files) { 
     /* note: "nothing" is older than all possible times */ 
     if (that file's packet's time is newer than packet time) { 
      make that file's packet the one to process next; 
      packet time = that packet's time; 
     } 
    } 
    /*Do some processing on the packet we selected, eg to find an IP*/ 
    if (compareIP) 
     pcap_dump(pktMatch, &pktHeader, pktData); 
    mark the file whose packet we selected as not having a packet yet; 
}   
+0

감사합니다. Mr Guy! 나는 그것을하려고 노력할 것이다! 어쨌든 당신의 제안에 감사드립니다! – CheeHow

+0

Mr Guy, 어떻게'새로운 pcap을 pcap 목록에 추가하여 읽을 것인가? ' 그것이 연결된 목록입니까? 예를 들어 1.pcap 파일을 가지고 있다면 1.pcap에 어떻게 추가 할 수 있습니까? – CheeHow

+0

배열로'pcap_t * input'을 어떻게 넣을 수 있습니까? 'pcap_t [] * input'는 pcap 목록을 유지합니까? – CheeHow