Fixes writes to the PCAP file.

An incorrect error checking caused an error when writing to the
PCAP file.
Append frames to PCAP after displaying the payload.

This append the frame to the PCAP file after displaying the payload.
This allows the full frame to be shown to the user with the payload included before
the program stops because of an IO error to the PCAP file.
Closes PCAP file on exit.

The PCAP file was closed when an error occured. However it wasn't closed
when the program exited because of a signal. This patch register the cleanup
function to these signals.
Fixes the program that stop because of a signal.

Any signal received by the program would cause an EINTR error on
blocking syscalls in the event loop. Most probably within the select syscall
where the event loop spends most of its time. This patch check for the
error code and continue execution when a signal is caught.
Fixes double free when exiting with a signal.

When a signal caused the program to exit and call the sig_cleanup
function, the exit call triggered the cleanup hook again so the
cleanup function was called twice. Hence the PCAP file being freed
twice. This patch removes the first call and relies on the exit
hook to trigger the cleanup function.