]> The Tcpdump Group git mirrors - libpcap/commitdiff
Suppress warnings if RPCAP_MIN_VERSION is 0.
authorGuy Harris <[email protected]>
Sat, 25 Nov 2017 11:03:58 +0000 (03:03 -0800)
committerGuy Harris <[email protected]>
Sat, 25 Nov 2017 11:03:58 +0000 (03:03 -0800)
Version numbers are unsigned, so they can never be < 0, so checking
whether a version is less than the minimum supported version will never
fail.

pcap-rpcap.c
rpcap-protocol.h
rpcapd/daemon.c

index f4d330c9ce2d98663755ef1016697602afaf7399..3ef4bc1e1b7a38d2b59d525edccd0374ef919f45 100644 (file)
@@ -1974,8 +1974,7 @@ static int rpcap_sendauth(SOCKET sock, uint8 *ver, struct pcap_rmtauth *auth, ch
                         *
                         * Do we also support it?
                         */
-                       if (header.ver < RPCAP_MIN_VERSION ||
-                           header.ver > RPCAP_MAX_VERSION)
+                       if (RPCAP_VERSION_IS_SUPPORTED(header.ver))
                        {
                                /*
                                 * No, so there's no version we both support.
index 7523a9e44a51f56eea4c0e7a2ff819340760b073..c78580f99bc946dd5004c8c299884faa36c57a92 100644 (file)
 #define RPCAP_MIN_VERSION 0
 #define RPCAP_MAX_VERSION 0
 
+/*
+ * Version numbers are unsigned, so if RPCAP_MIN_VERSION is 0, they
+ * are >= the minimum version, by definition; don't check against
+ * RPCAP_MIN_VERSION, as you may get compiler warnings that the
+ * comparison will always succeed.
+ */
+#if RPCAP_MIN_VERSION == 0
+#define RPCAP_VERSION_IS_SUPPORTED(v)  ((v) <= RPCAP_MAX_VERSION)
+#else
+#define RPCAP_VERSION_IS_SUPPORTED(v)  \
+       ((v) >= RPCAP_MIN_VERSION && (v) <= RPCAP_MAX_VERSION)
+#endif
+
 /*
  * Separators used for the host list.
  *
index 58314f8b74ce8f821204f58d066e13132160238b..f5255cdfa939a8dc56b0bb0e142f7b7e1e1b0160 100755 (executable)
@@ -237,14 +237,19 @@ void *daemon_serviceloop(void *ptr)
                //
                // Did the client specify a version we can handle?
                //
-               if (header.ver < RPCAP_MIN_VERSION ||
-                   header.ver > RPCAP_MAX_VERSION)
+               if (RPCAP_VERSION_IS_SUPPORTED(header.ver))
                {
                        //
                        // Tell them it's not a valid protocol version.
                        //
                        uint8 reply_version;
 
+                       //
+                       // If RPCAP_MIN_VERSION is 0, no version is too
+                       // old, as the oldest supported version is 0,
+                       // and there are no negative versions.
+                       //
+#if RPCAP_MIN_VERSION != 0
                        if (header.ver < RPCAP_MIN_VERSION)
                        {
                                //
@@ -261,6 +266,7 @@ void *daemon_serviceloop(void *ptr)
                                reply_version = header.ver;
                        }
                        else
+#endif
                        {
                                //
                                // Their maximum version is too new,