diff options
Diffstat (limited to 'freebsd/contrib/libpcap/savefile.c')
-rw-r--r-- | freebsd/contrib/libpcap/savefile.c | 69 |
1 files changed, 24 insertions, 45 deletions
diff --git a/freebsd/contrib/libpcap/savefile.c b/freebsd/contrib/libpcap/savefile.c index 8f6b17c7..6b0cc86e 100644 --- a/freebsd/contrib/libpcap/savefile.c +++ b/freebsd/contrib/libpcap/savefile.c @@ -31,21 +31,13 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif +#include <pcap-types.h> #ifdef _WIN32 -#include <pcap-stdinc.h> -#else /* _WIN32 */ -#if HAVE_INTTYPES_H -#include <inttypes.h> -#elif HAVE_STDINT_H -#include <stdint.h> -#endif -#ifdef HAVE_SYS_BITYPES_H -#include <sys/bitypes.h> -#endif -#include <sys/types.h> +#include <io.h> +#include <fcntl.h> #endif /* _WIN32 */ #include <errno.h> @@ -61,7 +53,7 @@ #endif #include "sf-pcap.h" -#include "sf-pcap-ng.h" +#include "sf-pcapng.h" #ifdef _WIN32 /* @@ -94,7 +86,7 @@ static pcap_t *pcap_fopen_offline(FILE *, char *); #endif static int -sf_getnonblock(pcap_t *p, char *errbuf) +sf_getnonblock(pcap_t *p _U_) { /* * This is a savefile, not a live capture file, so never say @@ -104,7 +96,7 @@ sf_getnonblock(pcap_t *p, char *errbuf) } static int -sf_setnonblock(pcap_t *p, int nonblock, char *errbuf) +sf_setnonblock(pcap_t *p, int nonblock _U_) { /* * This is a savefile, not a live capture file, so reject @@ -120,7 +112,7 @@ sf_setnonblock(pcap_t *p, int nonblock, char *errbuf) } static int -sf_stats(pcap_t *p, struct pcap_stat *ps) +sf_stats(pcap_t *p, struct pcap_stat *ps _U_) { pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Statistics aren't available from savefiles"); @@ -238,7 +230,7 @@ sf_inject(pcap_t *p, const void *buf _U_, size_t size _U_) * single device? IN, OUT or both? */ static int -sf_setdirection(pcap_t *p, pcap_direction_t d) +sf_setdirection(pcap_t *p, pcap_direction_t d _U_) { pcap_snprintf(p->errbuf, sizeof(p->errbuf), "Setting direction is not supported on savefiles"); @@ -255,22 +247,6 @@ sf_cleanup(pcap_t *p) pcap_freecode(&p->fcode); } -/* -* fopen's safe version on Windows. -*/ -#ifdef _MSC_VER -FILE *fopen_safe(const char *filename, const char* mode) -{ - FILE *fp = NULL; - errno_t errno; - errno = fopen_s(&fp, filename, mode); - if (errno == 0) - return fp; - else - return NULL; -} -#endif - pcap_t * pcap_open_offline_with_tstamp_precision(const char *fname, u_int precision, char *errbuf) @@ -295,14 +271,16 @@ pcap_open_offline_with_tstamp_precision(const char *fname, u_int precision, #endif } else { -#if !defined(_WIN32) && !defined(MSDOS) - fp = fopen(fname, "r"); -#else + /* + * "b" is supported as of C90, so *all* UN*Xes should + * support it, even though it does nothing. It's + * required on Windows, as the file is a binary file + * and must be read in binary mode. + */ fp = fopen(fname, "rb"); -#endif if (fp == NULL) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname, - pcap_strerror(errno)); + pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, + errno, "%s", fname); return (NULL); } } @@ -331,14 +309,16 @@ pcap_t* pcap_hopen_offline_with_tstamp_precision(intptr_t osfd, u_int precision, fd = _open_osfhandle(osfd, _O_RDONLY); if ( fd < 0 ) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, pcap_strerror(errno)); + pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, + errno, "_open_osfhandle"); return NULL; } file = _fdopen(fd, "rb"); if ( file == NULL ) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, pcap_strerror(errno)); + pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, + errno, "_fdopen"); return NULL; } @@ -375,7 +355,7 @@ pcap_fopen_offline_with_tstamp_precision(FILE *fp, u_int precision, /* * Read the first 4 bytes of the file; the network analyzer dump - * file formats we support (pcap and pcap-ng), and several other + * file formats we support (pcap and pcapng), and several other * formats we might support in the future (such as snoop, DOS and * Windows Sniffer, and Microsoft Network Monitor) all have magic * numbers that are unique in their first 4 bytes. @@ -383,9 +363,8 @@ pcap_fopen_offline_with_tstamp_precision(FILE *fp, u_int precision, amt_read = fread((char *)&magic, 1, sizeof(magic), fp); if (amt_read != sizeof(magic)) { if (ferror(fp)) { - pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, - "error reading dump file: %s", - pcap_strerror(errno)); + pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE, + errno, "error reading dump file"); } else { pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "truncated dump file; tried to read %lu file header bytes, only got %lu", |