]> The Tcpdump Group git mirrors - libpcap/commitdiff
Allow a platform to add information to the version string.
authorGuy Harris <[email protected]>
Tue, 16 May 2017 19:18:33 +0000 (12:18 -0700)
committerGuy Harris <[email protected]>
Tue, 16 May 2017 19:18:33 +0000 (12:18 -0700)
For example, on Linux, we add information about memory-mapped capture
support; see comments on GitHub issue #600.

16 files changed:
pcap-bpf.c
pcap-dag.c
pcap-dlpi.c
pcap-int.h
pcap-libdlpi.c
pcap-linux.c
pcap-nit.c
pcap-null.c
pcap-pf.c
pcap-septel.c
pcap-sita.c
pcap-snf.c
pcap-snit.c
pcap-snoop.c
pcap.c
pcap_version.h.in

index 5e3fe31a31cde5c99f664d324a224669e59a3015..38844887846b4440e3c4ace9792fb8c676b3651d 100644 (file)
@@ -3149,3 +3149,16 @@ pcap_set_datalink_bpf(pcap_t *p, int dlt)
 #endif
        return (0);
 }
+
+/*
+ * Platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+#ifdef HAVE_ZEROCOPY_BPF
+       return ("with zerocopy support");
+#else
+       return (NULL);
+#endif
+}
index d9a03b51a1299828ca621b5b9b4f12cea1621f1d..80ed01a2714c5c544a7c8c72c991da1d250bbe80 100644 (file)
@@ -1348,4 +1348,13 @@ pcap_create_interface(const char *device, char *errbuf)
            "This version of libpcap only supports DAG cards");
        return NULL;
 }
+
+/*
+ * Platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return ("DAG-only");
+}
 #endif
index dc243752c11e2db267b13a87e48b4885dff24cc3..436008d1b877ced4ad5037a4006b4cc498510e11 100644 (file)
@@ -1835,3 +1835,12 @@ pcap_create_interface(const char *device _U_, char *ebuf)
        p->activate_op = pcap_activate_dlpi;
        return (p);
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
index 052c24892ecf79da7dac5ff0a8df3e3ed4e6266f..66c3d0634c1e8247c43b851592fe9e64637636c1 100644 (file)
@@ -389,6 +389,14 @@ int        pcap_getnonblock_fd(pcap_t *);
 int    pcap_setnonblock_fd(pcap_t *p, int);
 #endif
 
+/*
+ * Internal interfaces for "pcap_lib_version()".
+ *
+ * "pcap_platform_lib_version()" returns platform-specific version
+ * information, or NULL if there isn't any.
+ */
+const char *pcap_platform_lib_version(void);
+
 /*
  * Internal interfaces for "pcap_create()".
  *
index d004f62e740d03470fc50b8f11255881559a079e..d2386d79fa973a8e46c09795bf416652e891ade7 100644 (file)
@@ -450,3 +450,12 @@ pcap_create_interface(const char *device _U_, char *ebuf)
        p->activate_op = pcap_activate_libdlpi;
        return (p);
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
index 1ee10ddba623b71a23a449c9ce93b22db30f18f3..ae29bf576be1f1e0bb541c8b54fae92619a9656f 100644 (file)
@@ -6916,3 +6916,22 @@ reset_kernel_filter(pcap_t *handle)
        return 0;
 }
 #endif
+
+/*
+ * Platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+#ifdef HAVE_PACKET_RING
+ #if defined(HAVE_TPACKET3)
+       return ("with TPACKET_V{1,2,3} support");
+ #elif defined(HAVE_TPACKET2)
+       return ("with TPACKET_V{1,2} support");
+ #else
+       return ("with TPACKET_V1 support");
+ #endif
+#else
+       return ("without TPACKET support");
+#endif
+}
index 19f10fc3e8c8e1132d56a5f7826811065d5da410..b18f815515654684029d1e35b1022f3100bce83b 100644 (file)
@@ -382,3 +382,12 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
 {
        return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound));
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
index de20f227c311cf6cf7c063fd33e54c466f5ce12c..887e218053987bd0b6fd3e1f01c2c16dace30227 100644 (file)
@@ -50,3 +50,12 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
         */
        return (0);
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
index 97a33023ff5c8f9dbf4c5d2a6fc032a3e1887c73..0c2d0a6fe5ce027457f17d8aa3ee7152e062022c 100644 (file)
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -620,3 +620,12 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
        pf->filtering_in_kernel = 0;
        return (0);
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
index 8d7b5555b885bb2514107982102ab5ed00c65110..b5f6127ec2b6557df6b9701bc0e9043332f6d9bb 100644 (file)
@@ -319,4 +319,13 @@ pcap_create_interface(const char *device, char *errbuf)
                 "This version of libpcap only supports Septel cards");
   return (NULL);
 }
+
+/*
+ * Platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return ("Septel-only");
+}
 #endif
index 075aee777a6a64e34d453b2e31b0c2fdd966c150..1e12491c5aecbc4ea5eabcb9eabf6d68217753d9 100644 (file)
@@ -1047,3 +1047,12 @@ int pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) {
        //printf("pcap_findalldevs() returning ZERO OK\n");                             // fulko
        return 0;
 }
+
+/*
+ * Platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return ("SITA-only");
+}
index f482935fbef2de8bb1c8484a255c5b1ffbcf6c1c..e3d364a4fb80cf7969702193f0d662756530386a 100644 (file)
@@ -582,4 +582,13 @@ pcap_create_interface(const char *device, char *errbuf)
            "This version of libpcap only supports SNF cards");
        return NULL;
 }
+
+/*
+ * Platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return ("SNF-only");
+}
 #endif
index 0c00860b47071760c8b1ef52b477b9b2025617e5..6471ec4781dc5a7ddea063d9a171ce18ffa99361 100644 (file)
@@ -458,3 +458,12 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
 {
        return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound));
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
index 5eab4a2d66e05dcafb8ddac2e27aa579f4f71025..2f57fcdb44d804948feacba3aacddc5439243e19 100644 (file)
@@ -433,3 +433,12 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
 {
        return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound));
 }
+
+/*
+ * No platform-specific information.
+ */
+const char *
+pcap_platform_lib_version(void)
+{
+       return (NULL);
+}
diff --git a/pcap.c b/pcap.c
index a47e361390655848ddb2e4d30651e62f0f601efa..488846d5a53f2338d463b894e68f8517faa8c4fe 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -2963,9 +2963,9 @@ pcap_offline_filter(const struct bpf_program *fp, const struct pcap_pkthdr *h,
 
 #include "pcap_version.h"
 
-#ifdef _WIN32
+static const char *pcap_lib_version_string;
 
-static char *full_pcap_version_string;
+#ifdef _WIN32
 
 #ifdef HAVE_VERSION_H
 /*
@@ -2990,8 +2990,9 @@ pcap_lib_version(void)
 {
        char *packet_version_string;
        size_t full_pcap_version_string_len;
+       char *full_pcap_version_string;
 
-       if (full_pcap_version_string == NULL) {
+       if (pcap_lib_version_string == NULL) {
                /*
                 * Generate the version string.
                 */
@@ -3038,8 +3039,9 @@ pcap_lib_version(void)
                            packet_version_string,
                            pcap_version_string);
                }
+               pcap_lib_version_string = full_pcap_version_string;
        }
-       return (full_pcap_version_string);
+       return (pcap_lib_version_string);
 }
 
 #else /* HAVE_VERSION_H */
@@ -3055,8 +3057,9 @@ pcap_lib_version(void)
 {
        char *packet_version_string;
        size_t full_pcap_version_string_len;
+       char *full_pcap_version_string;
 
-       if (full_pcap_version_string == NULL) {
+       if (pcap_lib_version_string == NULL) {
                /*
                 * Generate the version string.  Report the packet.dll
                 * version.
@@ -3074,24 +3077,24 @@ pcap_lib_version(void)
                    pcap_version_string_packet_dll_fmt,
                    pcap_version_string,
                    packet_version_string);
+               pcap_lib_version_string = full_pcap_version_string;
        }
-       return (full_pcap_version_string);
+       return (pcap_lib_version_string);
 }
 
 #endif /* HAVE_VERSION_H */
 
 #elif defined(MSDOS)
 
-static char *full_pcap_version_string;
-
 const char *
-pcap_lib_version (void)
+pcap_lib_version(void)
 {
        char *packet_version_string;
        size_t full_pcap_version_string_len;
+       char *full_pcap_version_string;
        static char dospfx[] = "DOS-";
 
-       if (full_pcap_version_string == NULL) {
+       if (pcap_lib_version_string == NULL) {
                /*
                 * Generate the version string.
                 */
@@ -3103,8 +3106,9 @@ pcap_lib_version (void)
                        return (NULL);
                strcpy(full_pcap_version_string, dospfx);
                strcat(full_pcap_version_string, pcap_version_string);
+               pcap_lib_version_string = full_pcap_version_string;
        }
-       return (full_pcap_version_string);
+       return (pcap_lib_version_string);
 }
 
 #else /* UN*X */
@@ -3112,7 +3116,43 @@ pcap_lib_version (void)
 const char *
 pcap_lib_version(void)
 {
-       return (pcap_version_string);
+       const char *platform_version_string;
+       size_t full_pcap_version_string_len;
+       char *full_pcap_version_string;
+
+       if (pcap_lib_version_string == NULL) {
+               /*
+                * Generate the version string.
+                * Get any platform-specific information.
+                *
+                * XXX - what about all the local capture modules other
+                * that the "native interface" one?  That could make
+                * the version string really long.
+                */
+               platform_version_string = pcap_platform_lib_version();
+               if (platform_version_string == NULL) {
+                       /*
+                        * No platform-specific information.
+                        */
+                       pcap_lib_version_string = pcap_version_string;
+               } else {
+                       /*
+                        * Add on the platform-specific information.
+                        */
+                       full_pcap_version_string_len =
+                           strlen(pcap_version_string) + 2 + strlen(platform_version_string) + 1 + 1;
+                       full_pcap_version_string =
+                           malloc(full_pcap_version_string_len);
+                       if (full_pcap_version_string == NULL)
+                               return (NULL);
+                       pcap_snprintf(full_pcap_version_string,
+                           full_pcap_version_string_len,
+                           "%s (%s)", pcap_version_string,
+                           platform_version_string);
+                       pcap_lib_version_string = full_pcap_version_string;
+               }
+       }
+       return (pcap_lib_version_string);
 }
 #endif
 
index 3104c8ea1579494a06a920a95ace9b9e5c586a5b..187bc160f352486991c9a90e0d8cff83eb966c93 100644 (file)
@@ -9,5 +9,8 @@
  * being the one from the version of the library with which the program
  * was linked, or even weirder things, such as the string being the one
  * from the library but being truncated).
+ *
+ * In addition, we may add additional information to this string, so
+ * pcap_lib_version() might not return this string alone anyway.
  */
 static const char pcap_version_string[] = "libpcap version %%LIBPCAP_VERSION%%";