summaryrefslogtreecommitdiff
path: root/rpcapd/rpcapd.c
Commit message (Collapse)AuthorAgeFilesLines
* Don't tell the client if we can't turn non-blocking mode off.Guy Harris2019-01-071-3/+9
| | | | | | | | | | | If the control socket is in non-blocking mode, there's no guarantee that we can easily send an error message to the client - we *probably* can, but let's not rely on it, especially given that there are "shouldn't happen" errors. Log them instead. While we're at it, fix a copy-and-pasteo and fix indentation. (cherry picked from commit 40b4666b567b234a5d8c2ae802c290d49758834a)
* Squelch warnings about unreachable code.Guy Harris2018-11-211-2/+2
| | | | | | | | | | | C copmilers *really* shouldn't complain about unreachable break statements, given that they're used as case separators. *Maybe* complain if they're immediately preceded by a return or break statement, but not if they're preceded by calls to functions that don't return. While we're at it, use the same style for all NOTREACHED comments. (cherry picked from commit 69b2b73b57863b270ca9479c136b158242dd08df)
* Provide out own strlcpy() and strlcat() routines if necessary.Guy Harris2018-10-171-5/+5
| | | | | | | | | | | | | | | | We now depend on the *full* semantics of those routines, including the return value being usable for truncation checks. If we're building for a UN*X that has them, define pcap_strl{cpy,cat} to be strl{cpy,cat}. If we're building for Windows using MSVC, define pcap_strl{cpy,cat}, not strl{cpy,cat}. Otherwise, build our won versions of pcap_strl{cpy,cat} from BSD-derived source code. (cherry picked from commit 017c240336a375aebd52ec30cf341a207f1c12a4)
* We don't need execute permission for source files.Guy Harris2018-05-251-0/+0
|
* Add manpage content from ↵Joerg Mayer2018-04-201-3/+3
| | | | https://www.winpcap.org/docs/docs_412/html/group__remote.html
* Fix a few warnings that came up after turning on a dozen more warningsJoerg Mayer2018-04-041-1/+1
|
* Fix the byte order of the port in log messages.Guy Harris2018-04-041-2/+2
|
* Log warnings for failures to open a socket, and fail if we have no sockets.Guy Harris2018-04-041-1/+42
|
* Squelch a signed vs. unsigned comparison warning on FreeBSD 10.Guy Harris2018-04-041-1/+2
| | | | | | | FD_SETSIZE might be defined as an unsigned, but sock_info->sock will be an int on UN*Xes. It's not going to be negative (that's used for errors from calls that return FDs, and if we got an error we wouldn't have an FD on which to select), so just cast both sides to unsigned int.
* Enable -Wunused-parameter and fix warnings that are almost trivial.Joerg Mayer2018-04-021-3/+4
| | | | Signed-off-by: Joerg Mayer <jmayer@loplof.de>
* Merge pull request #685 from jmayer/add-staticGuy Harris2018-04-021-5/+5
|\ | | | | Declare some variables static (found via -Wmissing-variable-declarations)
| * Declare some variables static (found via -Wmissing-variable-declarations)Joerg Mayer2018-04-011-5/+5
| |
* | Get rid of a redundant #endif/#ifndef pair.Guy Harris2018-04-011-2/+0
| | | | | | | | | | | | | | | | | | | | That makes it #ifdef _WIN32 Windows-only stuff #else UN*X-only stuff #endif
* | Rename SOCK_MESSAGE() to SOCK_DEBUG_MESSAGE().Guy Harris2018-04-011-13/+13
| | | | | | | | | | | | | | This emphasizes that it's for *debugging* messages, not for errors sent to the peer or logged to a daemon log file. Any message that would be useful if printed/logged in a production environment should *not* be reported with SOCK_DEBUG_MESSAGE().
* | Add support for running rpcapd from inetd and inetd-alikes.Guy Harris2018-04-011-59/+185
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When run from inetd and programs that support inetd-style program launching (xinetd, launchd, systemd, ...), we don't do a connection-accept loop; we're handed the input side of the connection as the standard input and the output side of the connection as the standard output, and should dive right into the service loop. We extract the initial connection initialization and cleanup stuff from daemon_serviceloop() and put it into the code that calls the service loop, in rpcapd.c; it's different in the four cases where we start a service loop (accepted connection on UN*X, accepted connection on Windows, run from inetd, active mode), so that cleans up daemon_serviceloop() a bit. Supply a sample launchd plist; we could also supply examples of inetd and xinetd config file entries, and systemd units.
* | Rename SOCK_ASSERT to SOCK_MESSAGEJoerg Mayer2018-04-011-17/+14
| | | | | | | | | | SOCK_ASSERT was always called with a true expression ("1") thus only ever executing the message part. Rename the macro, remove the assert part and remove the "1" parameter.
* | Clean up handling of the state change event.Guy Harris2018-04-011-24/+3
| | | | | | | | | | | | | | We don't need to make it a manual-reset event, explicitly check it with WaitForSingleObject(), and reset it; it's the first event in the event set, so if it's set, WSAWaitForMultipleEvents() will return WSA_WAIT_EVENT_0, otherwise it'll return some other value.
* | On Windows, only re-read the configuration file in the main accept loop.Guy Harris2018-04-011-36/+78
|/ | | | | | | | That's what we do on UN*X; it should keep us from changing configuration information out from under that loop. While we're at it, indicate that we'll accept "parameter change" controls, because we have code to process them.
* Terminate rpcapd-as-a-service the same way it's done with ^C.Guy Harris2018-04-011-44/+22
| | | | | | | | | Call send_shutdown_event() on a SERVICE_CONTROL_STOP opcode. Handle the SERVICE_CONTROL_PARAMCHANGE opcode as well. Also, close all the listen sockets and clean up the socket mechanism before accept_connections() returns.
* Note that calling exit() appears to kill even blocked threads.Guy Harris2018-04-011-1/+8
|
* Turn off non-blocking mode on the socket we got from accept().Guy Harris2018-03-311-1/+25
| | | | | | | | | | | Doing WSAEventSelect() on a socket turns on non-blocking mode on that socket. accept(), on a non-blocking socket, returns a non-blocking socket and, if the listen socket is non-blocking because WSAEventSelect() was done on it, returns a non-blocking socket *with WSAEventSelect() in effect*, so you have to remove the events and then turn off non-blocking mode. Thanks, Microsoft.
* Don't declare main() with a third envp argument.Guy Harris2018-03-311-1/+1
| | | | | | | ISO C doesn't say it can have that argument, and the argument isn't used. The Single UNIX Specification says a pointer to the environment is available as an external variable, and says nothing about a third envp argument.
* Don't re-read the configuration file in a signal handler.Guy Harris2018-03-301-4/+35
| | | | | | | | | | Instead, have the SIGHUP handler set a flag indicating that the configuration file should be re-read, and have the main loop check that flag and, if it's set, clear the flag and call fileconf_read(). Don't set the handler in fileconf_read() - we're using sigaction() and telling it that the handler shouldn't be reset, so there's no need to set it, and setting it might clear the "don't reset" indication.
* Make flags set in signal handlers volatile sig_atomic_t.Guy Harris2018-03-301-1/+1
| | | | | Behavior, if a variable is set in a signal handler, is undefined unless the variable is of type volatile sig_atomic_t.
* Use sigaction(), not signal(), to catch signals on UN*X.Guy Harris2018-03-301-6/+28
| | | | | | | We don't want to rely on signal() not resetting the signal handler. The Single UNIX Specification says it's implementation-defined whether that happens. Use sigaction(), instead, where, if you don't request that the signal handler be reset, it's not reset.
* Redo the main event loop of rpcapd.Guy Harris2018-03-301-182/+467
| | | | | | | | | | | | | | | | Have the main thread wait on all of the sockets on which we're listening, using select() on UN*X and WSAWaitForMultipleEvents() on Windows, rather than having separate threads or processes for each of the sockets. On UN*X, have "shut down" signals just set a flag, and have the select() check for EINTR and, if it got EINTR, check the flag, and leave the main event loop if it's set. On Windows, set a console control event handler and, for all the "shut down" events, set an event on which the main thread waits, in addition to the socket events, and, if that event is signaled, leave the main event loop.
* Fix MSVC build.Guy Harris2018-03-281-2/+2
| | | | | Again, the "decl" in "__declspec()" appears to mean it's for use only in declarations, not definitions.
* Add -Wmissing-noreturn to compiler warnings and fix all fixable warnings.Joerg Mayer2018-03-281-1/+1
| | | | | | | | Also suppress the one non-fixable warning: build/scanner.c:5020:1: warning: function 'yy_fatal_error' could be declared with attribute 'noreturn' [-Wmissing-noreturn] Signed-off-by: Joerg Mayer <jmayer@loplof.de>
* Squelch "constant in conditional expression" warnings.Guy Harris2018-03-201-3/+3
| | | | Use for (;;) rather than while (1).
* Try to cope better with SIGPIPE.Guy Harris2018-03-181-0/+3
| | | | | | | | If we have the SO_NOSIGPIPE socket option, set it on all sockets created with sock_open(). Ignore SIGPIPE in rpcapd, in case we're on a platform where we *can't* disable SIGPIPE on a socket.
* Free the socket temporary when appropriate.Guy Harris2018-01-211-3/+19
| | | | | | | | | | | | | | If we're using threads, free it if the attempt to create the thread fails. If we're using subprocesses, free it in the parent process, which isn't using it. (We don't really teed the socket temporary if we're using subprocesses, as the socket value won't be overwritten - the multiple socket opens are done in separate processes.) This should fix Coverity CID 1418994.
* Free addrinfo in the child after forking.Guy Harris2018-01-211-0/+1
| | | | This should fix Coverity CID 1418993.
* Rename rpcapd/utils.[ch] to getopt.[ch] and build it only on Windows.Guy Harris2017-11-261-1/+1
| | | | It's just a version of getopt() to use on Windows.
* stat() is the name of a UN*X system API; don't use it as a variable name.Guy Harris2017-11-251-2/+2
| | | | That squelches some warnings.
* Add a routine to format error messages with an errno-based message at the end.Guy Harris2017-11-151-3/+7
| | | | | | | | | | | | | | That routine will use strerror_s() or strerror_r() if available, in a fashion that's thread-safe. Otherwise, it falls back on pcap_strerror(). Use it in both libpcap and rpcapd. Given that we check for errors in strerror_r(), hopefully this will squelch warnings with newer version of GCC and GNU libc; whilst the macOS (and other BSD-flavored?) strerror_r() always fills in a message, that's not required by the Single UNIX Specification, as far as I can tell, so we apparently really *do* need to check for errors.
* Missing semicolon.Guy Harris2017-11-101-1/+1
|
* Clean up signal handling.Guy Harris2017-11-101-38/+61
| | | | | | | | | | | | | Have separate handlers for SIGINT/SIGTERM, for which we just want to kill off subprocesses on UN*X and exit on all platforms (just exit, don't muck with sockets, as that could cause random errors in threads handling connections), and SIGABRT, which is for Windows services and which probably needs more cleanup. Change signal handler names to better felect what they (now) do, and add and update comments. No need to export the handlers from rpcapd/rpcapd.c
* More error logging improvements.Guy Harris2017-11-101-1/+3
| | | | | If we're not checking whether a sock_close() fails, we don't need an error message.
* Cast the result of _beginthreadex() to HANDLE.Guy Harris2017-11-101-2/+2
|
* Don't leak thread handles.Guy Harris2017-11-101-0/+3
| | | | | These threads just run in the background; we don't need to wait for them to finish, so close the handle as soon as we've gotten it.
* Include <process.h> as needed.Guy Harris2017-11-101-8/+10
|
* Use pcap_snprintf in rpcapd.Guy Harris2017-11-101-6/+6
| | | | That way, we get the same semantics on Windows and UN*X.
* Use native Windows threads directly on Windows.Guy Harris2017-11-101-52/+42
| | | | | That's one fewer tool you have to go run out and get in order to assemble the motorocycle engine you picked up from Ikea.
* Fix "sleep forever" and "sleep for N seconds".Guy Harris2017-11-011-2/+8
| | | | | | | | To block a thread forever (or, on UN*X, until a signal), use Sleep(INFINITE) on Windows and pause() on UN*X. To block a thread for N seconds, use Sleep(N*1000) on Windows and sleep(N) on UN*X.
* Fix a couple more rpcap_senderror() calls.Guy Harris2017-10-311-2/+2
|
* Redo the message processing in the client, add protocol version negotiation.Guy Harris2017-10-311-1/+1
| | | | | | Currently, we only have one protocol version, but the code should be able to handle multiple versions in the future - and to be able to work with older code that doesn't do negotiation.
* Remove trailing white space.Guy Harris2017-10-291-41/+41
|
* Fix "warning: ISO C90 forbids mixed declarations and code"Francois-Xavier Le Bail2017-10-211-2/+2
|
* Bounds-check an array index before using the index.Guy Harris2017-10-101-1/+1
| | | | Fixes Coverity CID 1419001.
* socket() and accept() return INVALID_SOCKET on errors.Guy Harris2017-10-071-3/+3
| | | | | | | | | | On Windows, you're supposed to check against INVALID_SOCKET. On UN*X, you're supposed to check against -1, but, on UN*X, we define INVALID_SOCKET to be -1 so you can compare against INVALID_SOCKET on both platforms. That means that sock_open() should return INVALID_SOCKET on errors as well.