Retrieving local addresses with libnet
Within the libnet library, there are a number of instances where you will need the local addresses (hardware and/or IP addresses). If we were sending a packet, we will need to know the hardware address of the device at the Link layer. For the IP headers, we need to know the IP addresses (either IPv4 or IPv6) so that we can put it in the Source Address
field.
In this recipe, we will show how to retrieve and display the hardware, IPv4, and IPv6 addresses using libnet.
Getting ready
Prior to running the examples in the chapter, we will need to download and install libnet (see the Installing libnet recipe of this chapter). You will also need to add libnet to your project (see the Adding libnet to your project recipe of this chapter.
If we wish to run our project within Xcode, we will need to change the scheme Debug Process As setting to run as root, as described in the Introduction section of this chapter.
How to do it…
Let's get the local addresses of our device...