check_and_add_compiler_option(-Wmissing-variable-declarations)
check_and_add_compiler_option(-Wshadow)
check_and_add_compiler_option(-Wsign-compare)
+ check_and_add_compiler_option(-Wshorten-64-to-32)
check_and_add_compiler_option(-Wstrict-prototypes)
check_and_add_compiler_option(-Wunreachable-code)
check_and_add_compiler_option(-Wunused-parameter)
}
],
[generates warnings from ntohs()])
+ AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
fi
AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
#
$as_echo "no" >&6; }
CFLAGS="$save_CFLAGS"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports the -Wshorten-64-to-32 option" >&5
+$as_echo_n "checking whether the compiler supports the -Wshorten-64-to-32 option... " >&6; }
+ save_CFLAGS="$CFLAGS"
+ if expr "x-Wshorten-64-to-32" : "x-W.*" >/dev/null
+ then
+ CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error -Wshorten-64-to-32"
+ elif expr "x-Wshorten-64-to-32" : "x-f.*" >/dev/null
+ then
+ CFLAGS="$CFLAGS -Werror -Wshorten-64-to-32"
+ elif expr "x-Wshorten-64-to-32" : "x-m.*" >/dev/null
+ then
+ CFLAGS="$CFLAGS -Werror -Wshorten-64-to-32"
+ else
+ CFLAGS="$CFLAGS -Wshorten-64-to-32"
+ fi
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+return 0
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ can_add_to_cflags=yes
+ #
+ # The compile supports this; do we have some C code for
+ # which the warning should *not* appear?
+ # We test the fourth argument because the third argument
+ # could contain quotes, breaking the test.
+ #
+ if test "x" != "x"
+ then
+ CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wshorten-64-to-32 " >&5
+$as_echo_n "checking whether -Wshorten-64-to-32 ... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ #
+ # Not a problem.
+ #
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+else
+
+ #
+ # A problem.
+ #
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ can_add_to_cflags=no
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
+ CFLAGS="$save_CFLAGS"
+ if test x"$can_add_to_cflags" = "xyes"
+ then
+ V_CCOPT="$V_CCOPT -Wshorten-64-to-32"
+ fi
+
+else
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ CFLAGS="$save_CFLAGS"
+
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
*/
b0 = gen_linktype(cstate, LLCSAP_ISONS<<8 | LLCSAP_ISONS);
/* OSI in C-HDLC is stuffed with a fudge byte */
- b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, (long)v);
+ b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 1, BPF_B, (bpf_int32)v);
gen_and(b0, b1);
return b1;
default:
b0 = gen_linktype(cstate, LLCSAP_ISONS);
- b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, (long)v);
+ b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 0, BPF_B, (bpf_int32)v);
gen_and(b0, b1);
return b1;
}
* 4 is the offset of the PDU type relative to the IS-IS
* header.
*/
- b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, (long)v);
+ b1 = gen_cmp(cstate, OR_LINKPL_NOSNAP, 4, BPF_B, (bpf_int32)v);
gen_and(b0, b1);
return b1;
} else
#endif
{
- cc = read(p->fd, p->buffer, p->bufsize);
+ cc = (int)read(p->fd, p->buffer, p->bufsize);
}
if (cc < 0) {
/* Don't choke when we get ptraced */
*/
if (p->break_loop) {
p->bp = bp;
- p->cc = ep - bp;
+ p->cc = (int)(ep - bp);
/*
* ep is set based on the return value of read(),
* but read() from a BPF device doesn't necessarily
bp += BPF_WORDALIGN(caplen + hdrlen);
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt)) {
p->bp = bp;
- p->cc = ep - bp;
+ p->cc = (int)(ep - bp);
/*
* See comment above about p->cc < 0.
*/
static int
pcap_inject_bpf(pcap_t *p, const void *buf, size_t size)
{
- int ret;
+ 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);
+ }
ret = write(p->fd, buf, size);
#ifdef __APPLE__
errno, "send");
return (PCAP_ERROR);
}
- return (ret);
+ return ((int)ret);
}
#ifdef _AIX
* 'timeout', in pcap_t, is in milliseconds; we have to convert it into sec and microsec
*/
tv.tv_sec = p->opt.timeout / 1000;
- tv.tv_usec = (p->opt.timeout - tv.tv_sec * 1000) * 1000;
+ tv.tv_usec = (suseconds_t)((p->opt.timeout - tv.tv_sec * 1000) * 1000);
/* Watch out sockdata to see if it has input */
FD_ZERO(&rfds);
#include <errno.h> // for the errno variable
#include <stdlib.h> // for malloc(), free(), ...
#include <string.h> // for strlen(), ...
+#include <limits.h> // for INT_MAX
#ifdef _WIN32
#include <process.h> // for threads
//
// So we don't need to make sure that sendbufsize will overflow.
//
+ // However, we *do* need to make sure its value fits in an int,
+ // because sock_send() can't send more than INT_MAX bytes (it could
+ // do so on 64-bit UN*Xes, but can't do so on Windows, not even
+ // 64-bit Windows, as the send() buffer size argument is an int
+ // in Winsock).
+ //
sendbufsize = sizeof(struct rpcap_header) + sizeof(struct rpcap_pkthdr) + pcap_snapshot(session->fp);
+ if (sendbufsize > INT_MAX)
+ {
+ rpcapd_log(LOGPRIO_ERROR,
+ "Buffer size for this child thread would be larger than %d",
+ INT_MAX);
+ sendbuf = NULL; // we haven't allocated a buffer, so nothing to free
+ goto error;
+ }
sendbuf = (char *) malloc (sendbufsize);
if (sendbuf == NULL)
{
// Bufferize the general header
if (sock_bufferize(NULL, sizeof(struct rpcap_header), NULL,
- &sendbufidx, sendbufsize, SOCKBUF_CHECKONLY, errbuf,
+ &sendbufidx, (int)sendbufsize, SOCKBUF_CHECKONLY, errbuf,
PCAP_ERRBUF_SIZE) == -1)
{
rpcapd_log(LOGPRIO_ERROR,
// Bufferize the pkt header
if (sock_bufferize(NULL, sizeof(struct rpcap_pkthdr), NULL,
- &sendbufidx, sendbufsize, SOCKBUF_CHECKONLY, errbuf,
+ &sendbufidx, (int)sendbufsize, SOCKBUF_CHECKONLY, errbuf,
PCAP_ERRBUF_SIZE) == -1)
{
rpcapd_log(LOGPRIO_ERROR,
// Bufferize the pkt data
if (sock_bufferize((char *) pkt_data, pkt_header->caplen,
- sendbuf, &sendbufidx, sendbufsize, SOCKBUF_BUFFERIZE,
+ sendbuf, &sendbufidx, (int)sendbufsize, SOCKBUF_BUFFERIZE,
errbuf, PCAP_ERRBUF_SIZE) == -1)
{
rpcapd_log(LOGPRIO_ERROR,
{
char *pos;
int num = 0;
- int len, i;
+ size_t len, i;
while ((pos = strchr(string, chr)) != NULL)
{
struct pcap_sf_pkthdr sf_hdr;
f = (FILE *)user;
- sf_hdr.ts.tv_sec = h->ts.tv_sec;
+ /*
+ * Better not try writing pcap files after
+ * 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.caplen = h->caplen;
sf_hdr.len = h->len;
* don't have it, either?
*/
typedef int socklen_t;
+
+ /*
+ * Winsock doesn't have this POSIX type; it's used for the
+ * tv_usec value of struct timeval.
+ */
+ typedef long suseconds_t;
#else
/* UN*X */
#include <stdio.h>