aboutsummaryrefslogtreecommitdiff
path: root/testprogs/selpolltest.c
Commit message (Collapse)AuthorAgeFilesLines
* make some compilers be quiet about un-initialized variable, as per #982Michael Richardson2020-12-291-1/+1
|
* On Linux, return error on interface going away, not just going down.Guy Harris2020-01-291-28/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a pain to detect, because the PF_PACKET socket code appears to get separate "interface went down" and "interface went away" notifications in my "unplug a USB Wi-Fi adapter" tests on my VMware Fusion Ubuntu 18.04 virtual machine (5.3.0 kernel), and the first notification delivers a wakeup and returns ENETDOWN while the second notificaiton delivers *no* wakeup and sets the ifindex member of the struct packet_sock for the socket, so there's nothing we can test after the wakeup that's guaranteed to indicate that the interface has disappeared. So what we have to do is remember the ENETDOWN but not return it as an error, and then arrange to periodically check whether the interface is still there; if it isn't, we *then* return the "interface went away" error, and, if we see traffic or see that the interface is up, we clear the remembered ENETDOWN and stop doing the periodic checks. This is tricky, because it needs to work not only for blocking pcap_t's, where we're in a loop doing poll() calls, so we can keep checking within the loop, but also for non-blocking pcap_t's on which the caller is doing select()/poll()/epoll_wait(). In order to make *that* work, we need to tweak the semantics of pcap_get_required_select_timeout() so that it's not guaranteed that it will always return the same value, so that it should be called within event loops rather than called once outside the event loop. Normally, there is no timeout required for Linux PF_PACKET sockets, but when we're doing the periodic tests, the timeout is required. While we're doing that, we make the return value of pcap_get_required_select_timeout() a const pointer - there was no good reason for the caller to modify it (it doesn't belong to the caller). If poll() returns POLLERR, use getsockopt(SO_ERROR) to get the socket error, rather than a read(). Update the documentation to reflect this, and make various other cleanups (including documenting the error return value for pcap_get_selectable_fd() to -1 rather than PCAP_ERROR - it's not an error code, it's just a specific error value). Also note that, for kqueues on *BSD/macOS and for select/poll on Linux, the timeout needn't be used as a timeout for the call - you can have a timer, so that when that *particular* timer fires, you try calling pcap_dispatch() on the pcap_t to which it corresponds. Update selpolltest to add more capabilities needed when testing this on Linux. This should address GitHub issue #859 and pull request #858.
* Use correct function name in outputting error information.Nan Xiao2019-11-151-1/+1
|
* Fix data types.Guy Harris2018-09-151-1/+1
| | | | | | If you're accumulating the lengths of strings, as returned by strlen(), and passing the result to malloc(), it should be accumulated in a size_t.
* Squelch more narrowing warnings.Guy Harris2018-09-121-1/+1
|
* Fix a few warnings that came up after turning on a dozen more warningsJoerg Mayer2018-04-041-1/+1
|
* Fix a set of trivial unused warningsJoerg Mayer2018-04-041-2/+2
|
* Rename the test program directory to testprogs.Guy Harris2018-02-061-0/+443
We may have a directory of test files in the future, and we'd want to call it "tests", paralleling tcpdump's directory of test files.