Internally, we're using encodings in which ASCII characters are
represented in a single byte, so message strings must be "ANSI", not
"Unicode". Yes, that means they'll be in the current code page, which
isn't necessarily - and probably isn't - UTF-8, but Windows really
doesn't seem to provide much support for UTF-8 as a representation of
Unicode (the current code page isn't necessarily 65001, i.e. UTF-8,
especially given that some software appears to have problems with that
code page on at least some versions of Windows).
See GitHub issue pynetwork/pypcap#64.
(cherry picked from commit
a5341c3b81a4d7f00b5318c6d8fa8673eda81611)
size_t errlen;
char *p;
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
PCAP_ERRBUF_SIZE, NULL);
/*
int error;
error = GetLastError();
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
PCAP_ERRBUF_SIZE, NULL);
return -1;
int error;
error = GetLastError();
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
PCAP_ERRBUF_SIZE, NULL);
CloseHandle(Token);
int val;
val = GetLastError();
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, val, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR) string, PCAP_ERRBUF_SIZE, NULL);
{
#ifdef _WIN32
int retval;
- TCHAR message[SOCK_ERRBUF_SIZE]; /* It will be char (if we're using ascii) or wchar_t (if we're using unicode) */
+ char message[SOCK_ERRBUF_SIZE]; /* We're forcing "ANSI" */
if (errbuf == NULL)
return;
- retval = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
+ retval = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
NULL, errcode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
message, sizeof(message) / sizeof(TCHAR), NULL);