Solved

Writing payload to a file

Posted on 2010-08-29
1
569 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
1 Comment
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now