]> The Tcpdump Group git mirrors - libpcap/commitdiff
bpf: make the BPF device number unsigned.
authorGuy Harris <[email protected]>
Tue, 12 Jul 2022 21:08:41 +0000 (14:08 -0700)
committerGuy Harris <[email protected]>
Thu, 14 Jul 2022 05:20:13 +0000 (22:20 -0700)
It's unlikely that we'll try 2^31-1 devices without success and overflow
to 2^31, but this is cleaner (and BPF devices won't have negative device
numbers).

That means the buffer for the device name doesn't need to leave room for
the minus sign; that's what the compiler was warning about.

(cherry picked from commit 7610a61d72c818067a1e51f150b81ee7d489a577)

pcap-bpf.c

index 6a8e77470ce91a4a5196e0ded2e4d790b6ea0d6c..2898e598d8e3916c598c6535d79c9851b008d6b0 100644 (file)
@@ -478,8 +478,8 @@ bpf_open(char *errbuf)
 {
        int fd = -1;
        static const char cloning_device[] = "/dev/bpf";
-       int n = 0;
-       char device[sizeof "/dev/bpf00000000000"];
+       u_int n = 0;
+       char device[sizeof "/dev/bpf0000000000"];
        static int no_cloning_bpf = 0;
 
 #ifdef _AIX
@@ -526,7 +526,7 @@ bpf_open(char *errbuf)
                 * that isn't in use.
                 */
                do {
-                       (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++);
+                       (void)snprintf(device, sizeof(device), "/dev/bpf%u", n++);
                        /*
                         * Initially try a read/write open (to allow the inject
                         * method to work).  If that fails due to permission