Chapter 4. Using Libpcap

In this chapter, we will cover:

  • Adding libpcap to your project
  • Retrieving network device information
  • Capturing packets
  • Decoding Ethernet headers
  • Decoding IP headers
  • Decoding ARP headers
  • Decoding TCP headers
  • Decoding UDP headers
  • Decoding ICMP headers
  • Filtering packets
  • Saving a capture file
  • Creating a simple port scanner using libnet and libpcap together

Introduction

In the previous chapter, we discussed libnet, which is a library for constructing and injecting individual network packets. Being able to create and inject packets into the network is a very powerful feature, but to really make it useful, we need to be able to read the packets that come back. This is where libpcap comes in.

Note

While it is possible to compile libpcap for iOS ...

Get iOS and OS X Network Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.