Creating the Cpcap module
For our first example, we will be creating a utility that will list the default network device on the system the application is running on using the pcap library. For this utility, we will use the pcap_lookupdev() function from the pcap library. The man page for the pcap_lookupdev() function shows that we will need to import the pcap/pcap.h header file.
If you cannot pull up the pcap_lookupdev man page on your system, you might not have libpcap-dev installed. To install it using apt-get, run the following command:
sudo apt-get install libpcap-dev
To create the module, let's start off by creating the directory and files that we need:
mkdir Cpcap cd Cpcap touch Package.swift touch module.modulemap
Now we will need to define the pcap headers in the module.modulemap file. To do this, we put the following code into module.modulemap file:
module Cpcap [system] {
module libpcap {
header "/usr/include/pcap.h"
link "pcap"
...