Solved

Writing payload to a file

Posted on 2010-08-29
1
563 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

772 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

12 Experts available now in Live!

Get 1:1 Help Now