diff options
Diffstat (limited to 'pcap-new.c')
| -rw-r--r-- | pcap-new.c | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/pcap-new.c b/pcap-new.c index e61cf6ab2e9b..76388a998fd5 100644 --- a/pcap-new.c +++ b/pcap-new.c @@ -36,6 +36,7 @@ #endif #include "ftmacros.h" +#include "diag-control.h" /* * sockutils.h may include <crtdbg.h> on Windows, and pcap-int.h will @@ -88,7 +89,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t if (strlen(source) > PCAP_BUF_SIZE) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The source string is too long. Cannot handle it correctly."); + snprintf(errbuf, PCAP_ERRBUF_SIZE, "The source string is too long. Cannot handle it correctly."); return -1; } @@ -119,7 +120,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t if (*alldevs == NULL) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + snprintf(errbuf, PCAP_ERRBUF_SIZE, "No interfaces found! Make sure libpcap/Npcap is properly installed" " on the local machine."); return -1; @@ -209,7 +210,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t } /* Save the path for future reference */ - pcap_snprintf(path, sizeof(path), "%s", name); + snprintf(path, sizeof(path), "%s", name); pathlen = strlen(path); #ifdef _WIN32 @@ -224,7 +225,7 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t if (filehandle == INVALID_HANDLE_VALUE) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path); + snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path); return -1; } @@ -237,7 +238,10 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t if (filedata == NULL) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path); + DIAG_OFF_FORMAT_TRUNCATION + snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path); + DIAG_ON_FORMAT_TRUNCATION + closedir(unixdir); return -1; } #endif @@ -249,11 +253,13 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t /* Skip the file if the pathname won't fit in the buffer */ if (pathlen + strlen(filedata.cFileName) >= sizeof(filename)) continue; - pcap_snprintf(filename, sizeof(filename), "%s%s", path, filedata.cFileName); + snprintf(filename, sizeof(filename), "%s%s", path, filedata.cFileName); #else if (pathlen + strlen(filedata->d_name) >= sizeof(filename)) continue; - pcap_snprintf(filename, sizeof(filename), "%s%s", path, filedata->d_name); + DIAG_OFF_FORMAT_TRUNCATION + snprintf(filename, sizeof(filename), "%s%s", path, filedata->d_name); + DIAG_ON_FORMAT_TRUNCATION #endif fp = pcap_open_offline(filename, errbuf); @@ -268,6 +274,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t PCAP_ERRBUF_SIZE, errno, "malloc() failed"); pcap_freealldevs(*alldevs); +#ifdef _WIN32 + FindClose(filehandle); +#else + closedir(unixdir); +#endif return -1; } @@ -297,6 +308,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t if (pcap_createsrcstr(tmpstring, PCAP_SRC_FILE, NULL, NULL, filename, errbuf) == -1) { pcap_freealldevs(*alldevs); +#ifdef _WIN32 + FindClose(filehandle); +#else + closedir(unixdir); +#endif return -1; } @@ -307,6 +323,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t PCAP_ERRBUF_SIZE, errno, "malloc() failed"); pcap_freealldevs(*alldevs); +#ifdef _WIN32 + FindClose(filehandle); +#else + closedir(unixdir); +#endif return -1; } @@ -321,6 +342,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t PCAP_ERRBUF_SIZE, errno, "malloc() failed"); pcap_freealldevs(*alldevs); +#ifdef _WIN32 + FindClose(filehandle); +#else + closedir(unixdir); +#endif return -1; } @@ -334,9 +360,11 @@ int pcap_findalldevs_ex(const char *source, struct pcap_rmtauth *auth, pcap_if_t #endif -#ifdef _WIN32 /* Close the search handle. */ +#ifdef _WIN32 FindClose(filehandle); +#else + closedir(unixdir); #endif return 0; @@ -370,7 +398,7 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, if (strlen(source) > PCAP_BUF_SIZE) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "The source string is too long. Cannot handle it correctly."); + snprintf(errbuf, PCAP_ERRBUF_SIZE, "The source string is too long. Cannot handle it correctly."); return NULL; } @@ -444,17 +472,19 @@ pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, return fp; fail: + DIAG_OFF_FORMAT_TRUNCATION if (status == PCAP_ERROR) - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", + snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", name, fp->errbuf); else if (status == PCAP_ERROR_NO_SUCH_DEVICE || status == PCAP_ERROR_PERM_DENIED || status == PCAP_ERROR_PROMISC_PERM_DENIED) - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", + snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s (%s)", name, pcap_statustostr(status), fp->errbuf); else - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", + snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", name, pcap_statustostr(status)); + DIAG_ON_FORMAT_TRUNCATION pcap_close(fp); return NULL; } |
