简体   繁体   English

为C中捕获的数据包创建PCAP文件

[英]create PCAP file for captured packet in c

I am working on a tool though which I am able to capture incoming packets (l2 buffer and L2 length, payload) in an interface and I am able to print that packet on console. 我正在使用一种工具,但是我可以在接口中捕获传入的数据包(l2缓冲区和L2长度,有效负载),并且可以在控制台上打印该数据包。 Now I want to write these packets to a pcap file so that I can transfer this file to other platform and read packet info. 现在,我想将这些数据包写入pcap文件,以便可以将该文件传输到其他平台并读取数据包信息。

How I can open a pcap file and write packet buffer to pcap file? 如何打开pcap文件并将数据包缓冲区写入pcap文件? How can I fill struct pcap_file_header ? 如何填充struct pcap_file_header

use pcap_dump to save the packet... this code might be useful :) 使用pcap_dump保存数据包...此代码可能有用:)

http://file-hub.com/cmd:thread/140400 http://file-hub.com/cmd:thread/140400

以下文档将lib_pcap您使用lib_pcap http://www.tcpdump.org/pcap.html捕获数据包

For writing pcap use library pcap_file_generator 要编写pcap,请使用库pcap_file_generator

Using: 使用:

int i=0;
  const int  PKTS_COUNT = 212000;
  int PKTS_LEN =  540;
  static ethernet_data_t  eda;
  eda.len = PKTS_LEN;

  PCAPFILE * pfl = lpcap_create("./pcaplibtestfile.pcap");
  for( i=0;i< PKTS_COUNT;i++ )
  {
    /* TODO:  fill data   memcpy(eda.data , YOUR_DATA_BUF,SIZE_YOUR_DATA_BUF  );
       eda.len = SIZE_YOUR_DATA_BUF;
    */
   lpcap_write_data( pfl , &eda , i, 0 );
  }
  lpcap_close_file( pfl );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM