?
Solved

Writing payload to a file

Posted on 2010-08-29
1
Medium Priority
?
574 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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

762 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