summaryrefslogtreecommitdiff
path: root/pcap-rpcap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-04-11 14:40:01 -0700
committerGuy Harris <guy@alum.mit.edu>2020-04-11 14:40:01 -0700
commit028ce6676bcfc813e581f95f4797666043cb5475 (patch)
tree7ec277f2a64042ed8f288705f646fa7d3dd7c02f /pcap-rpcap.c
parent8e8cb61cb313f43faf586b3f824b05eb67430b31 (diff)
downloadlibpcap-028ce6676bcfc813e581f95f4797666043cb5475.tar.gz
Add support for UTF-8 strings on Windows.
Add a routine pcap_init() that initializes pcap, specifying whether strings should be treated as being in UTF-8 or a local character encoding. On UN*Xes, we don't change our behavior based on that setting; if there is ever an issue with local character encodings *other* than UTF-8, we can use it. On Windows, the local character encoding is the local ANSI code page; if pcap_init() isn't called, or is called with PCAP_CHAR_ENC_LOCAL, strings are treated as being in the current ANSI code page, as before, otherwise they're treated as being in UTF-8. This includes file path names and error messages. In addition, if pcap_init() is called, regardless of the options, we disable pcap_lookupdev(), making it always return NULL, as it retunred *UTF-16LE* strings (plural!) on Windows NT, and pcap_create() had to check for UTF-16LE strings to work around that. That workaround is unsafe (it will read past the end of the input string if the string is one ASCII character), and is also disabled if pcap_init() is called. We also make rpcapd send UTF-8 error message strings over the wire; sending local code page strings is a Bad Idea, as the client has no idea what the server's code page is. (Do not assume the client and server are necessarily in the same location.) Fix the capitalization of "Winsock" while we're at it; Microsoft appears to spell it "Winsock", rather than "WinSock".
Diffstat (limited to 'pcap-rpcap.c')
-rw-r--r--pcap-rpcap.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/pcap-rpcap.c b/pcap-rpcap.c
index f7999fe0..836681a1 100644
--- a/pcap-rpcap.c
+++ b/pcap-rpcap.c
@@ -46,6 +46,10 @@
#include "rpcap-protocol.h"
#include "pcap-rpcap.h"
+#ifdef _WIN32
+#include "charconv.h" /* for utf_8_to_acp_truncated() */
+#endif
+
#ifdef HAVE_OPENSSL
#include "sslutils.h"
#endif
@@ -2161,7 +2165,7 @@ rpcap_setup_session(const char *source, struct pcap_rmtauth *auth,
}
/* Warning: this call can be the first one called by the user. */
- /* For this reason, we have to initialize the WinSock support. */
+ /* For this reason, we have to initialize the Winsock support. */
if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1)
return -1;
@@ -2797,7 +2801,7 @@ SOCKET pcap_remoteact_accept_ex(const char *address, const char *port, const cha
hints.ai_socktype = SOCK_STREAM;
/* Warning: this call can be the first one called by the user. */
- /* For this reason, we have to initialize the WinSock support. */
+ /* For this reason, we have to initialize the Winsock support. */
if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1)
return (SOCKET)-1;
@@ -3353,6 +3357,15 @@ static void rpcap_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen, char *remote_e
*/
remote_errbuf[PCAP_ERRBUF_SIZE - 1] = '\0';
+#ifdef _WIN32
+ /*
+ * If we're not in UTF-8 mode, convert it to the local
+ * code page.
+ */
+ if (!pcap_utf_8_mode)
+ utf_8_to_acp_truncated(remote_errbuf);
+#endif
+
/*
* Throw away the rest.
*/