source and destination IP(v4) addresses and MAC addresses are the same
pdelong42 opened this issue · 1 comments
I don't properly handle the return values of ether_ntoa() and inet_ntoa(). Manpages for both explicitly say that the string is returned in a static buffer that will be overwritten by the next call. I read this and promptly forgot it (told you my C was rusty). Then I proceeded to call each twice in succession as args to a function call.
To remedy this, I need to use the re-entrant versions: ether_ntoa_r() and inet_ntoa_r(). For the latter, there's the alternative of using inet_ntop().
Incidentally, this does not affect the printing of IPv6 addresses, because those are translated using inet_ntop(), which does not use a shared static memory location (it requires the caller to pass-in a pre-allocated buffer).
I rewrote the ethernet address printing logic to copy the static-stored strings to a buffer on heap, and rewrote the IPv4 printing logic to use inet_ntop().
It might be interesting to try ether_ntoa_r() or inet_ntoa_r(), as a learning exercise, but it's not a high priority.