__pragma(warning(disable:4244)) \
__pragma(warning(disable:4702))
#define DIAG_ON_FLEX __pragma(warning(pop))
+
+ /*
+ * Suppress narrowing warnings.
+ */
+ #define DIAG_OFF_NARROWING \
+ __pragma(warning(push)) \
+ __pragma(warning(disable:4242))
+ #define DIAG_ON_NARROWING __pragma(warning(pop))
#elif PCAP_IS_AT_LEAST_CLANG_VERSION(2,8)
/*
* This is Clang 2.8 or later; we can use "clang diagnostic
PCAP_DO_PRAGMA(clang diagnostic push) \
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wsign-compare") \
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wdocumentation") \
+ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32") \
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wmissing-noreturn") \
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunused-parameter") \
PCAP_DO_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
#define DIAG_ON_FLEX \
PCAP_DO_PRAGMA(clang diagnostic pop)
+
+ /*
+ * Suppress the only narrowing warnings you get from Clang.
+ */
+ #define DIAG_OFF_NARROWING \
+ PCAP_DO_PRAGMA(clang diagnostic push) \
+ PCAP_DO_PRAGMA(clang diagnostic ignored "-Wshorten-64-to-32")
+
+ #define DIAG_ON_NARROWING \
+ PCAP_DO_PRAGMA(clang diagnostic pop)
#elif PCAP_IS_AT_LEAST_GNUC_VERSION(4,6)
/*
* This is GCC 4.6 or later, or a compiler claiming to be that.
PCAP_DO_PRAGMA(GCC diagnostic ignored "-Wunreachable-code")
#define DIAG_ON_FLEX \
PCAP_DO_PRAGMA(GCC diagnostic pop)
+
+ /*
+ * GCC currently doesn't issue any narrowing warnings.
+ */
+ #define DIAG_OFF_NARROWING
+ #define DIAG_ON_NARROWING
#else
/*
* Neither Visual Studio, nor Clang 2.8 or later, nor GCC 4.6 or later
*/
#define DIAG_OFF_FLEX
#define DIAG_ON_FLEX
+ #define DIAG_OFF_NARROWING
+ #define DIAG_ON_NARROWING
#endif
#ifdef YYBYACC
}
static int
-pcap_inject_bpf(pcap_t *p, const void *buf, size_t size)
+pcap_inject_bpf(pcap_t *p, const void *buf, int size)
{
- ssize_t ret;
-
- /*
- * We return the number of bytes written, so the number of
- * bytes to write must fit in an int.
- */
- if (size > INT_MAX) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
- errno, "More than %d bytes cannot be injected", INT_MAX);
- return (PCAP_ERROR);
- }
+ int ret;
- ret = write(p->fd, buf, size);
+ ret = (int)write(p->fd, buf, size);
#ifdef __APPLE__
if (ret == -1 && errno == EAFNOSUPPORT) {
/*
/*
* Now try the write again.
*/
- ret = write(p->fd, buf, size);
+ ret = (int)write(p->fd, buf, size);
}
#endif /* __APPLE__ */
if (ret == -1) {
errno, "send");
return (PCAP_ERROR);
}
- return ((int)ret);
+ return (ret);
}
#ifdef _AIX
/* forward declaration */
static int bt_activate(pcap_t *);
static int bt_read_linux(pcap_t *, int , pcap_handler , u_char *);
-static int bt_inject_linux(pcap_t *, const void *, size_t);
+static int bt_inject_linux(pcap_t *, const void *, int);
static int bt_setdirection_linux(pcap_t *, pcap_direction_t);
static int bt_stats_linux(pcap_t *, struct pcap_stat *);
return -1;
}
- pkth.caplen = ret;
+ pkth.caplen = (bpf_u_int32)ret;
/* get direction and timestamp*/
cmsg = CMSG_FIRSTHDR(&msg);
}
static int
-bt_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_)
+bt_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_)
{
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on "
"bluetooth devices");
return -1;
}
- pkth.caplen = ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header);
+ pkth.caplen = (bpf_u_int32)(ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header));
pkth.len = pkth.caplen;
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
}
static int
-bt_monitor_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
+bt_monitor_inject(pcap_t *handle, const void *buf _U_, int size _U_)
{
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported yet");
return -1;
}
static int
-dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
+dag_inject(pcap_t *p, const void *buf _U_, int size _U_)
{
strlcpy(p->errbuf, "Sending packets isn't supported on DAG cards",
PCAP_ERRBUF_SIZE);
}
static int
-dbus_write(pcap_t *handle, const void *buf, size_t size)
+dbus_write(pcap_t *handle, const void *buf, int size)
{
/* XXX, not tested */
struct pcap_dbus *handlep = handle->priv;
}
static int
-pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
+pcap_inject_dlpi(pcap_t *p, const void *buf, int size)
{
#ifdef DL_HP_RAWDLS
struct pcap_dlpi *pd = p->priv;
typedef int (*can_set_rfmon_op_t)(pcap_t *);
typedef int (*read_op_t)(pcap_t *, int cnt, pcap_handler, u_char *);
typedef int (*next_packet_op_t)(pcap_t *, struct pcap_pkthdr *, u_char **);
-typedef int (*inject_op_t)(pcap_t *, const void *, size_t);
+typedef int (*inject_op_t)(pcap_t *, const void *, int);
typedef void (*save_current_filter_op_t)(pcap_t *, const char *);
typedef int (*setfilter_op_t)(pcap_t *, struct bpf_program *);
typedef int (*setdirection_op_t)(pcap_t *, pcap_direction_t);
/* Forwards. */
static int dlpromiscon(pcap_t *, bpf_u_int32);
static int pcap_read_libdlpi(pcap_t *, int, pcap_handler, u_char *);
-static int pcap_inject_libdlpi(pcap_t *, const void *, size_t);
+static int pcap_inject_libdlpi(pcap_t *, const void *, int);
static void pcap_libdlpi_err(const char *, const char *, int, char *);
static void pcap_cleanup_libdlpi(pcap_t *);
}
static int
-pcap_inject_libdlpi(pcap_t *p, const void *buf, size_t size)
+pcap_inject_libdlpi(pcap_t *p, const void *buf, int size)
{
struct pcap_dlpi *pd = p->priv;
int retv;
static int pcap_can_set_rfmon_linux(pcap_t *);
static int pcap_read_linux(pcap_t *, int, pcap_handler, u_char *);
static int pcap_read_packet(pcap_t *, pcap_handler, u_char *);
-static int pcap_inject_linux(pcap_t *, const void *, size_t);
+static int pcap_inject_linux(pcap_t *, const void *, int);
static int pcap_stats_linux(pcap_t *, struct pcap_stat *);
static int pcap_setfilter_linux(pcap_t *, struct bpf_program *);
static int pcap_setdirection_linux(pcap_t *, pcap_direction_t);
genlmsg_put(msg, 0, 0, genl_family_get_id(state->nl80211), 0,
0, NL80211_CMD_NEW_INTERFACE, 0);
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
+DIAG_OFF_NARROWING
NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, mondevice);
+DIAG_ON_NARROWING
NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MONITOR);
err = nl_send_auto_complete(state->nl_sock, msg);
char buffer[512];
char * bufptr;
FILE * file;
- int field_to_convert = 3, if_name_sz = strlen(if_name);
+ int field_to_convert = 3;
+ size_t if_name_sz = strlen(if_name);
long int dropped_pkts = 0;
file = fopen("/proc/net/dev", "r");
#ifdef HAVE_TPACKET3
struct utsname utsname;
char *version_component, *endp;
- int major, minor;
+ long major, minor;
int broken_tpacket_v3 = 1;
/*
#else /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI) */
socklen_t fromlen;
#endif /* defined(HAVE_PACKET_AUXDATA) && defined(HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI) */
- int packet_len, caplen;
+ ssize_t packet_len;
+ int caplen;
struct pcap_pkthdr pcap_header;
struct bpf_aux_data aux_data;
* we were told to break out of the loop.
*/
handle->break_loop = 0;
- return PCAP_ERROR_BREAK;
- }
+ return PCAP_ERROR_BREA }
#if defined(HAVE_PACKET_AUXDATA) && defined(HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC);
if (handlep->vlan_offset != -1) {
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
struct tpacket_auxdata *aux;
- unsigned int len;
+ size_t len;
struct vlan_tag *tag;
if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) ||
continue;
}
- len = (u_int)packet_len > iov.iov_len ? iov.iov_len : (u_int)packet_len;
- if (len < (u_int)handlep->vlan_offset)
+ len = (size_t)packet_len > iov.iov_len ? iov.iov_len : (u_int)packet_len;
+ if (len < (size_t)handlep->vlan_offset)
break;
/*
}
static int
-pcap_inject_linux(pcap_t *handle, const void *buf, size_t size)
+pcap_inject_linux(pcap_t *handle, const void *buf, int size)
{
struct pcap_linux *handlep = handle->priv;
int ret;
}
#endif
- ret = send(handle->fd, buf, size, 0);
+ ret = (int)send(handle->fd, buf, size, 0);
if (ret == -1) {
pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
errno, "send");
/*
* Get the status field of the ring buffer frame at a specified offset.
*/
-static inline int
+static inline u_int
pcap_get_ring_frame_status(pcap_t *handle, int offset)
{
struct pcap_linux *handlep = handle->priv;
h.raw = RING_GET_FRAME_AT(handle, offset);
switch (handlep->tp_version) {
case TPACKET_V1:
- return (h.h1->tp_status);
+ /*
+ * This is an unsigned long, but only the lower 32
+ * bits are used.
+ */
+ return (u_int)(h.h1->tp_status);
break;
case TPACKET_V1_64:
- return (h.h1_64->tp_status);
+ /*
+ * This is an unsigned long in the kernel, which is 64-bit,
+ * but only the lower 32 bits are used.
+ */
+ return (u_int)(h.h1_64->tp_status);
break;
#ifdef HAVE_TPACKET2
case TPACKET_V2:
struct pcap_netfilter *handlep = handle->priv;
register u_char *bp, *ep;
int count = 0;
- int len;
+ ssize_t len;
/*
* Has "pcap_breakloop()" been called?
*/
if (handle->break_loop) {
handle->bp = bp;
- handle->cc = ep - bp;
+ handle->cc = (int)(ep - bp);
if (count == 0) {
handle->break_loop = 0;
return PCAP_ERROR_BREAK;
* buffer.
*/
if (msg_len > ep - bp)
- msg_len = ep - bp;
+ msg_len = (uint32_t)(ep - bp);
bp += msg_len;
if (count >= max_packets && !PACKET_COUNT_IS_UNLIMITED(max_packets)) {
handle->bp = bp;
- handle->cc = ep - bp;
+ handle->cc = (int)(ep - bp);
if (handle->cc < 0)
handle->cc = 0;
return count;
}
static int
-netfilter_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_)
+netfilter_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_)
{
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on netfilter devices");
return (-1);
/* ignore interrupt system call error */
do {
- len = recvfrom(handle->fd, buf, sizeof(buf), 0, (struct sockaddr *) &snl, &addrlen);
+ /*
+ * The buffer is not so big that its size won't
+ * fit into an int.
+ */
+ len = (int)recvfrom(handle->fd, buf, sizeof(buf), 0, (struct sockaddr *) &snl, &addrlen);
} while ((len == -1) && (errno == EINTR));
if (len <= 0)
/* XXX need to check the NIOCTXSYNC/poll */
static int
-pcap_netmap_inject(pcap_t *p, const void *buf, size_t size)
+pcap_netmap_inject(pcap_t *p, const void *buf, int size)
{
struct pcap_netmap *pn = p->priv;
struct nm_desc *d = pn->d;
}
static int
-pcap_inject_nit(pcap_t *p, const void *buf, size_t size)
+pcap_inject_nit(pcap_t *p, const void *buf, int size)
{
struct sockaddr sa;
int ret;
/* Send a packet to the network */
static int
-pcap_inject_npf(pcap_t *p, const void *buf, size_t size)
+pcap_inject_npf(pcap_t *p, const void *buf, int size)
{
struct pcap_win *pw = p->priv;
PACKET pkt;
* "pcap_inject()" is expected to return the number of bytes
* sent.
*/
- return ((int)size);
+ return (size);
}
static void
}
static int
-pcap_inject_pf(pcap_t *p, const void *buf, size_t size)
+pcap_inject_pf(pcap_t *p, const void *buf, int size)
{
int ret;
int numdev;
size_t namelen;
const char *port;
- unsigned port_num;
+ unsigned long port_num;
int i;
pcap_t *p = NULL;
static int
-septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
+septel_inject(pcap_t *handle, const void *buf _U_, int size _U_)
{
strlcpy(handle->errbuf, "Sending packets isn't supported on Septel cards",
PCAP_ERRBUF_SIZE);
//printf("acn_start_monitor() complete\n"); // fulko
}
-static int pcap_inject_acn(pcap_t *p, const void *buf _U_, size_t size _U_) {
+static int pcap_inject_acn(pcap_t *p, const void *buf _U_, int size _U_) {
strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters",
PCAP_ERRBUF_SIZE);
return (-1);
}
static int
-snf_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
+snf_inject(pcap_t *p, const void *buf _U_, int size _U_)
{
#ifdef SNF_HAVE_INJECT_API
struct pcap_snf *ps = p->priv;
}
static int
-pcap_inject_snit(pcap_t *p, const void *buf, size_t size)
+pcap_inject_snit(pcap_t *p, const void *buf, int size)
{
struct strbuf ctl, data;
}
static int
-pcap_inject_snoop(pcap_t *p, const void *buf, size_t size)
+pcap_inject_snoop(pcap_t *p, const void *buf, int size)
{
int ret;
static int usb_read_linux(pcap_t *, int , pcap_handler , u_char *);
static int usb_read_linux_bin(pcap_t *, int , pcap_handler , u_char *);
static int usb_read_linux_mmap(pcap_t *, int , pcap_handler , u_char *);
-static int usb_inject_linux(pcap_t *, const void *, size_t);
+static int usb_inject_linux(pcap_t *, const void *, int);
static int usb_setdirection_linux(pcap_t *, pcap_direction_t);
static void usb_cleanup_linux_mmap(pcap_t *);
{
struct utsname utsname;
char *version_component, *endp;
- int major, minor, subminor;
+ long major, minor, subminor;
if (uname(&utsname) == 0) {
/*
struct pcap_usb_linux *handlep = handle->priv;
unsigned timestamp;
int tag, cnt, ep_num, dev_addr, dummy, ret, urb_len, data_len;
+ ssize_t read_ret;
char etype, pipeid1, pipeid2, status[16], urb_tag, line[USB_LINE_LEN];
char *string = line;
u_char * rawdata = handle->buffer;
/* ignore interrupt system call errors */
do {
- ret = read(handle->fd, line, USB_LINE_LEN - 1);
+ read_ret = read(handle->fd, line, USB_LINE_LEN - 1);
if (handle->break_loop)
{
handle->break_loop = 0;
return -2;
}
- } while ((ret == -1) && (errno == EINTR));
- if (ret < 0)
+ } while ((read_ret == -1) && (errno == EINTR));
+ if (read_ret < 0)
{
if (errno == EAGAIN)
return 0; /* no data there */
/* read urb header; %n argument may increment return value, but it's
* not mandatory, so does not count on it*/
- string[ret] = 0;
+ string[read_ret] = 0;
ret = sscanf(string, "%x %d %c %c%c:%d:%d %s%n", &tag, ×tamp, &etype,
&pipeid1, &pipeid2, &dev_addr, &ep_num, status,
&cnt);
return -1;
}
uhdr->ts_sec = pkth.ts.tv_sec;
- uhdr->ts_usec = pkth.ts.tv_usec;
+ uhdr->ts_usec = (int32_t)pkth.ts.tv_usec;
/* parse endpoint information */
if (pipeid1 == 'C')
}
static int
-usb_inject_linux(pcap_t *handle, const void *buf _U_, size_t size _U_)
+usb_inject_linux(pcap_t *handle, const void *buf _U_, int size _U_)
{
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on "
"USB devices");
/* read stats line */
do {
- ret = read(fd, string, USB_LINE_LEN-1);
- } while ((ret == -1) && (errno == EINTR));
+ read_ret = read(fd, string, USB_LINE_LEN-1);
+ } while ((read_ret == -1) && (errno == EINTR));
close(fd);
- if (ret < 0)
+ if (read_ret < 0)
{
pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't read stats from fd %d ", fd);
return -1;
}
- string[ret] = 0;
+ string[read_ret] = 0;
/* extract info on dropped urbs */
for (consumed=0; consumed < ret; ) {
int
pcap_sendpacket(pcap_t *p, const u_char *buf, int size)
{
+ if (size <= 0) {
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "The number of bytes to be sent must be positive", INT_MAX);
+ return (PCAP_ERROR);
+ }
+
if (p->inject_op(p, buf, size) == -1)
return (-1);
return (0);
int
pcap_inject(pcap_t *p, const void *buf, size_t size)
{
- return (p->inject_op(p, buf, size));
+ /*
+ * We return the number of bytes written, so the number of
+ * bytes to write must fit in an int.
+ */
+ if (size > INT_MAX) {
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "More than %d bytes cannot be injected", INT_MAX);
+ return (PCAP_ERROR);
+ }
+
+ if (size == 0) {
+ pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "The number of bytes to be injected must not be zero", INT_MAX);
+ return (PCAP_ERROR);
+ }
+
+ return (p->inject_op(p, buf, (int)size));
}
void
}
static int
-pcap_inject_dead(pcap_t *p, const void *buf _U_, size_t size _U_)
+pcap_inject_dead(pcap_t *p, const void *buf _U_, int size _U_)
{
pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"Packets can't be sent on a pcap_open_dead pcap_t");
#endif
static int
-sf_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
+sf_inject(pcap_t *p, const void *buf _U_, int size _U_)
{
strlcpy(p->errbuf, "Sending packets isn't supported on savefiles",
PCAP_ERRBUF_SIZE);
* 2038-01-19 03:14:07 UTC; switch to pcapng.
*/
sf_hdr.ts.tv_sec = (bpf_int32)h->ts.tv_sec;
- sf_hdr.ts.tv_usec = h->ts.tv_usec;
+ sf_hdr.ts.tv_usec = (bpf_int32)h->ts.tv_usec;
sf_hdr.caplen = h->caplen;
sf_hdr.len = h->len;
/* XXX we should check the return status */