The str_copy() function is designed to copy a maximum number of characters to a destination string and guarantee that the destination string is terminated. The str_duplicate() function is a wrapper that first allocates memory before copying the string.
Use pthread_sigmask() to block signals when creating the stats thread so only the main process handles them. This fixes a hang on exit bug in FreeBSD. Also, switch to using the -pthread gcc parameter for compiling which is supposed to be more portable.
Now -s is all it takes to enter rps stats mode. -t is still used to set the display interval, but it has a sane default. There are situations when it doesn't make sense to have to enter a display interval, plus this makes it easier to start seeing data.
This provides a cleaner interface to the main program and ensures that all initialization and cleanup logic is fired correctly. The stats display thread is also now only started when not reading a saved capture file. It didn't make as much sense to do a real-time display while parsing a local file and it led to different results depending on when the display thread fired.
This new implementation removes the previous hard limit on the number of hosts that could be tracked at one time. Now that number can scale to however many hosts are seen on the wire.
Use the header caplen value instead of len when determining the maximum length to increment as caplen should always be <= len, depending on snaplen. Also, we need to take the ethernet header into account.
run_stats function and refactor structs.
…-P) to specify the PID filename