aboutsummaryrefslogtreecommitdiff
path: root/sockutils.h
Commit message (Collapse)AuthorAgeFilesLines
* rpcap: fix sock_open() issues.Guy Harris2022-08-011-4/+13
| | | | | | | | | | | | | | | | | | | | | | | When connecting as a client, don't create one socket, using the address family of the first entry in the address list, and use that for all entries; on most if not all platforms, an AF_INET socket can't be used to connect to an IPv6 address and an AF_INET6 socket can't be used to connect to an IPv4 address. Instead, construct a table of the entries in the address list, sort it by address family, and cycle through the entries. If there is no socket yet, create it based on the current entry's address family; if there is a socket, but it's for a different address family than the current entry's address family, close it and open a new one. If connecting fails for all addresses, don't just construct a long barely-readable error message consisting of the full errors for each failure. Instead, construct one that, for each error code, has a list of the addresses that got that error code; if all the failures had the same error code, just show the host name, not the complete list of addresses. Clean up some error handling routines - fix names, allow some to take a printf-style argument list, etc..
* Clean up the arguments to sock_bufferize().Guy Harris2021-07-221-1/+1
| | | | | | | | | | | | | | | | Make the first argument a void * - it can point to anything, not just, for example, a character string. It's not a "buffer", it's just data, whatever that might be, so call it "data", not "buffer". Rename "tempbuf" to "outbuf" to indicate that it's a buffer location into which data is copied. In English, stuff would be contained in "data", not contained into "data" - into suggests that stuff is being copied into it by the routine, which isn't the case - and stuff isn't copied in "outbuf", it's copied into "outbuf". Update the comment for sock_bufferize() to reflect all this.
* Revert "Don't wrap chunks of headers with extern "C" { ... }."Guy Harris2021-03-171-35/+30
| | | | | | | This reverts commit 8b6b13d4cbb685db047af04c49817ed81fff7c35. That solution allowed you to intermix declarations/definitions and before the extern "C", so you can see what's being imported.
* Don't wrap chunks of headers with extern "C" { ... }.Guy Harris2021-03-171-30/+35
| | | | | | | | | | | Instead, explictly flag individual functions with extern "C" by adding it to the tag we're already using for exported functions, and creating a new tag to use for non-exported functions. Rename those tags, and the tags used for exported data, to say what they do, rather than saying "this is an API" (we may export things we don't want to be treated as part of the API, but that we have to export because some programs use them).
* Get rid of the last SOCK_DEBUG_MESSAGE() calls.Guy Harris2019-01-121-29/+0
| | | | | | | | | | | Treat a failure to get the socket buffer size as an error; we were just blithely driving on and using the variable into which the size *hadn't* been put. That means that our caller will be handed the error message; we presume they do something with it, so that we don't need to print it as a debugging message. In other cases, we already were reporting an error and providing the error message; the same applies there.
* Clean up sockutils.h.Guy Harris2019-01-111-31/+1
| | | | | | | | Get rid of definitions in sockutils.h that are also defined in pcap/socket.h. Have pcap/socket.h include the rough UN*X equivalents of <winsock.h> and <ws2tcpip.h>.
* Put the Windows-vs-non-Windows socket defines in <pcap/socket.h>.Guy Harris2019-01-091-21/+2
|
* Merge branch 'master' of https://github.com/rixed/libpcap into rixed-masterGuy Harris2019-01-061-4/+6
|\
| * TLS for rpcap: also encrypt the control socketCedric Cellier2018-09-131-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch also encode the control sockets in adition to the data socket. Clients performs a TLS handshake when the scheme is rpcaps:// rather than rpcap://. Both active and passive modes are supported, but transfert via UDP is not (yet) supported (the lib returns an error in that case). I did some adaptation to the windows code but couldn't tested so for all I know it may not even compile. Also tried to fix the indentation.
* | Add a flag to allow peeking at messages in sock_recv().Guy Harris2018-10-191-0/+2
|/ | | | | It works like MSG_PEEK (because it causes MSG_PEEK to be set in the recv() flags).
* Use -Wshorten-64-to-32 if it's available, and fix warnings it shows.Guy Harris2018-09-091-0/+6
| | | | | Probably harmless, but do it to help catch some issues on LP64 (64-bit UN*X) or LLP64 (64-bit Windows) platforms when compiling on macOS.
* Rename SOCK_MESSAGE() to SOCK_DEBUG_MESSAGE().Guy Harris2018-04-011-3/+3
| | | | | | | 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().
* Rename SOCK_ASSERT to SOCK_MESSAGEJoerg Mayer2018-04-011-4/+3
| | | | | 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.
* Redo the main event loop of rpcapd.Guy Harris2018-03-301-1/+1
| | | | | | | | | | | | | | | | 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.
* Make the size argument to sock_send() a size_t.Guy Harris2018-03-181-1/+2
| | | | | The equivalent argument to sock_recv() is a size_t; make sock_send() more like sock_recv(), for consistency.
* Clean up packet message reception.Guy Harris2017-11-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Have separate sockutils routines for reading from a stream socket and receiving messages from a datagram socket. The latter assumes you get the entire message in a single receive operation and checks for the datagram being bigger than the provided buffer. We don't need separate network and packet-to-provide-to-the-callback buffers; use the standard buffer for both purposes, making it big enough for the largest expected packet message. This eliminates a copy. Use the "receive messages from a datagram socket" routine for UDP data sockets. That way, we check for messages bigger than the largest expected packet message; add additional checks to make sure the packet is big enough to hold an rpcap header and, if so, that the packet length in the rpcap header isn't larger than the part of the message. Check for interrupted message receives in the "read a packet message" code path. If we get an invalid message from the server, discard the rest of it if it's sent over TCP. In the read routine, check for errors and, if we didn't get a packet and didn't get an error - which could be a timeout or an interrupted receive - check whether we were told to break out of the loop.
* Handle the client closing the connection better.Guy Harris2017-11-101-4/+8
| | | | | | On the server side, don't treat an immediate EOF when trying to read a message header as an error, just silently terminate the session. Treat EOFs after reading *some* of the message as an error.
* Move all the UN*X-vs-Windows-sockets stuff together.Guy Harris2017-10-071-22/+17
|
* No need to manually define _WINSOCKAPI_Ali Abdulkadir2017-10-021-8/+0
|
* Don't bother supporting pre-2005 Visual Studio.Guy Harris2017-09-281-1/+1
| | | | 2003 (or earlier!) called; it wants its Microsoft C compiler back.
* Don't call a socket variable "socket".Guy Harris2017-03-201-3/+3
| | | | That collides with the create-a-socket function socket().
* Remove trailing spaces/tabsFrancois-Xavier Le Bail2016-08-201-2/+2
|
* No sockutils.h API uses ssize_t, so define it in sockutils.c.Guy Harris2016-07-301-1/+0
|
* Re-impose some of Winsock's limitations on sock_recv().Guy Harris2016-07-301-1/+1
| | | | | | | | | In Winsock, recv() takes an int as the size argument and returns an int as a return value, so it can't read more than INT_MAX bytes. Have it take a size_t as an argument (so you don't have to cast away warnings about narrowing sizeof values), return an error if it's bigger than INT_MAX (which it can be even on ILP32 platforms, as size_t is unsigned), and have the count of remaining bytes be an int.
* Define ssize_t on Windows.Guy Harris2016-07-281-1/+6
|
* Define SOCKET and INVALID_SOCKET in remote-ext.h and sockutils.h.Guy Harris2016-07-281-86/+75
| | | | | | | That way, we don't require code that includes pcap/pcap.h to include sockutils.h if pcap/pcap.h is declaring functions that use SOCKET. Do other formatting cleanups while we're at it.
* Clean up sock_recv().Guy Harris2016-07-281-1/+1
| | | | | Give it a signature more like that of recv(), and make the main loop a for loop.
* Add back WinPcap specific functions to libpcap, the built wpcap.dll already ↵Yang Luo2016-07-261-0/+248
works with Wireshark.