[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Writing payload to a file

Posted on 2010-08-29
1
Medium Priority
?
575 Views
Last Modified: 2012-05-10
Hi guys,

Related to this question:

http://www.experts-exchange.com/Programming/Languages/C/Q_26433861.html

How can the payload be written out to another memory location or written to a disk.

Specifically I would like to emulate stream behaviour with the packets that come from pcap.
0
Comment
Question by:PMembrey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 33556193
For writing to a file, I recommend the pcap file format (it's pretty much the standard, so you'll be able to open and use the file with many other tools) :

        http://wiki.wireshark.org/Development/LibpcapFileFormat

Fortunately, the pcap library comes with functions to help with this :

        pcap_dump_open : opens a pcap file for writing
        pcap_dump : writes a packet to that file
        pcap_dump_close : closes the pcap file


If you just want to copy the payload to a memory buffer, you can simply use memcpy :

        memcpy(buffer, payload, payload_size);

Make sure that the buffer is large enough.

Take note of the 'off' member of the IP header, which indicates the offset of the data when it's spread out over multiple packets.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question