aboutsummaryrefslogtreecommitdiff
path: root/fmtutils.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2022-08-01 14:25:42 -0700
committerGuy Harris <gharris@sonic.net>2022-08-01 14:25:42 -0700
commit7c17b91f769ae3a2cef64f35d61a28fdf08220ae (patch)
tree19d93753e15be90071e4ea1acab8d9ed67f02293 /fmtutils.c
parent137e5c5ac9dd878ebe2e85ee18014378399ad7c4 (diff)
rpcap: fix sock_open() issues.
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..
Diffstat (limited to 'fmtutils.c')
-rw-r--r--fmtutils.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/fmtutils.c b/fmtutils.c
index 5c7ddadf..2d357624 100644
--- a/fmtutils.c
+++ b/fmtutils.c
@@ -270,13 +270,21 @@ pcap_fmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
const char *fmt, ...)
{
va_list ap;
+
+ va_start(ap, fmt);
+ pcap_vfmt_errmsg_for_errno(errbuf, errbuflen, errnum, fmt, ap);
+ va_end(ap);
+}
+
+void
+pcap_vfmt_errmsg_for_errno(char *errbuf, size_t errbuflen, int errnum,
+ const char *fmt, va_list ap)
+{
size_t msglen;
char *p;
size_t errbuflen_remaining;
- va_start(ap, fmt);
- vsnprintf(errbuf, errbuflen, fmt, ap);
- va_end(ap);
+ (void)vsnprintf(errbuf, errbuflen, fmt, ap);
msglen = strlen(errbuf);
/*
@@ -378,6 +386,16 @@ pcap_fmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
const char *fmt, ...)
{
va_list ap;
+
+ va_start(ap, fmt);
+ pcap_vfmt_errmsg_for_win32_err(errbuf, errbuflen, errnum, fmt, ap);
+ va_end(ap);
+}
+
+void
+pcap_vfmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
+ const char *fmt, va_list ap)
+{
size_t msglen;
char *p;
size_t errbuflen_remaining;
@@ -385,9 +403,7 @@ pcap_fmt_errmsg_for_win32_err(char *errbuf, size_t errbuflen, DWORD errnum,
wchar_t utf_16_errbuf[PCAP_ERRBUF_SIZE];
size_t utf_8_len;
- va_start(ap, fmt);
vsnprintf(errbuf, errbuflen, fmt, ap);
- va_end(ap);
msglen = strlen(errbuf);
/*