2

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. 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.

How I can open a pcap file and write packet buffer to pcap file? How can I fill struct pcap_file_header?

0

2 Answers 2

2

use pcap_dump to save the packet... this code might be useful :)

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

Sign up to request clarification or add additional context in comments.

2 Comments

I have packet buffer which I want to write to a pcap file
how are you reading the packets? If you use pcap_loop with a dispatch function the packet header and packet data will be passed to that function... do you want to share your code? you might get an answer that better suits your needs
0

For writing pcap use library 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 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.