Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Saving a capture file


There will be times when we want to capture packets and not view the results immediately. The libpcap library has functions to open and save the packets to a binary file. This file has the same format as a tcpdump save file.

Getting ready

Prior to running this recipe, we need to follow the Adding libpcap to your project recipe explained earlier in this chapter. We also need to go through the Capturing packets recipe. We will discuss how to modify the packet capture code in order to save the captured packets to a save file.

How to do it…

Let's save our captured packets to a file:

  1. We begin by defining a pcap_dumper_t pointer and creating a pcap_loop. This will be the pointer to our save file.

    In our packet capture code from the Capturing packets recipe of this chapter, we want to replace the pcap_loop statement with the following lines:

     pcap_dumper_t *dumpfile=pcap_dump_open(handle, "~/pcapdump.pcap");
     if(dumpfile==NULL){
         NSLog(@"Error opening output file");
         exit...