]> The Tcpdump Group git mirrors - libpcap/commitdiff
Add a "pcap_lib_version()" routine to return a version string for
authorguy <guy>
Tue, 11 Feb 2003 07:40:09 +0000 (07:40 +0000)
committerguy <guy>
Tue, 11 Feb 2003 07:40:09 +0000 (07:40 +0000)
libpcap; it generates the string at run time on the first call, so that
it's not a constant string - in at least some UNIXes, constant data in a
shared library is kept separate from the library code, and is bound into
applications linked with that library at link time, not at run time, so
a constant string (such as "pcap_version[]") can reflect the version of
the library with which the application was built, not the version with
which it's running.

Document it, in the hopes that vendors will be less likely to omit it
from their libpcaps (unlike "pcap_version[]", which is absent from some
vendors' libpcaps).

Makefile.in
pcap.3
pcap.c
pcap.h

index 0b94eb1dab1c5713ac5c8e1c7adac9bc0b452531..ff02d47cc6cf2a7a1720c0366fe077d785bf1f62 100644 (file)
@@ -17,7 +17,7 @@
 #  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 #
-# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.90 2003-02-11 01:46:05 guy Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/libpcap/Makefile.in,v 1.91 2003-02-11 07:40:09 guy Exp $ (LBL)
 
 #
 # Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -84,7 +84,7 @@ OBJ = $(PSRC:.c=.o) $(FSRC:.c=.o) $(CSRC:.c=.o) $(GENSRC:.c=.o) # $(LIBOBJS)
 HDR =  pcap.h pcap-int.h pcap-namedb.h pcap-nit.h pcap-pf.h \
        ethertype.h gencode.h gnuc.h
 GENHDR = \
-       tokdefs.h
+       tokdefs.h version.h
 
 TAGHDR = \
        pcap-bpf.h
@@ -129,6 +129,11 @@ version.c: $(srcdir)/VERSION
        @rm -f $@
        sed -e 's/.*/char pcap_version[] = "&";/' $(srcdir)/VERSION > $@
 
+version.h: $(srcdir)/VERSION
+       @rm -f $@
+       sed -e 's/\([0-9]*\)\.[0-9]*/#define VERSION_MAJOR \1/' $(srcdir)/VERSION > $@
+       sed -e 's/[0-9]*\.\([0-9]*\)/#define VERSION_MINOR \1/' $(srcdir)/VERSION >> $@
+
 bpf_filter.c: $(srcdir)/bpf/net/bpf_filter.c
        rm -f bpf_filter.c
        ln -s $(srcdir)/bpf/net/bpf_filter.c bpf_filter.c
diff --git a/pcap.3 b/pcap.3
index 34917fe6f583324760b036b32313d2929b94bbb0..018eb1c5a77522a94496289a6e75eb77abcd8a32 100644 (file)
--- a/pcap.3
+++ b/pcap.3
@@ -1,4 +1,4 @@
-.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap.3,v 1.45 2003-01-16 07:29:15 guy Exp $
+.\" @(#) $Header: /tcpdump/master/libpcap/Attic/pcap.3,v 1.46 2003-02-11 07:40:09 guy Exp $
 .\"
 .\" Copyright (c) 1994, 1996, 1997
 .\"    The Regents of the University of California.  All rights reserved.
@@ -96,6 +96,7 @@ int pcap_fileno(pcap_t *p)
 void pcap_perror(pcap_t *p, char *prefix)
 char *pcap_geterr(pcap_t *p)
 char *pcap_strerror(int error)
+const char *pcap_lib_version(void)
 .ft
 .LP
 .ft B
@@ -816,12 +817,10 @@ returns true if the current ``savefile'' uses a different byte order
 than the current system.
 .PP
 .B pcap_major_version()
-returns the major number of the version of the pcap used to write the
-savefile.
-.PP
+returns the major number of the file format of the savefile;
 .B pcap_minor_version()
-returns the minor number of the version of the pcap used to write the
-savefile.
+returns the minor number of the file format of the savefile.  The
+version number is stored in the header of the savefile.
 .PP
 .B pcap_file()
 returns the standard I/O stream of the ``savefile,'' if a ``savefile''
@@ -873,6 +872,10 @@ is provided in case
 .BR strerror (1)
 isn't available.
 .PP
+.B pcap_lib_version()
+returns a pointer to a string giving the version number of the libpcap
+library being used.
+.PP
 .B pcap_close()
 closes the files associated with
 .I p
diff --git a/pcap.c b/pcap.c
index cfcccf0c5c8f93a0602ea974913855afc4b816c9..4ef7914697d45751c018d11928703068a0d159d6 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -33,7 +33,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.45 2003-01-23 07:24:52 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.46 2003-02-11 07:40:09 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -60,6 +60,7 @@ static const char rcsid[] =
 #endif
 
 #include "pcap-int.h"
+#include "version.h"
 
 int
 pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
@@ -596,3 +597,25 @@ pcap_close(pcap_t *p)
        pcap_freecode(&p->fcode);
        free(p);
 }
+
+/*
+ * Generate the version string at run time, so that if libpcap is a
+ * shared library, it reflects the version of the library with
+ * which the program calling "pcap_lib_version()" is running, not
+ * the version with which it was built (on at least some UNIXes,
+ * constant data is linked in at build time).
+ */
+const char *
+pcap_lib_version(void)
+{
+       static char version_string[10+1+10+1];
+
+       if (version_string[0] == '\0') {
+               /*
+                * We haven't built the string yet.
+                */
+               snprintf(version_string, sizeof (version_string), "%u.%u",
+                   VERSION_MAJOR, VERSION_MINOR);
+       }
+       return (version_string);
+}
diff --git a/pcap.h b/pcap.h
index fbd3907fd17cc00af8ba28bf3b991a712ec639d6..146f1c1f931905fdbf1a98a9c89997cf6d5b06cc 100644 (file)
--- a/pcap.h
+++ b/pcap.h
@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.42 2003-02-11 01:46:06 guy Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.43 2003-02-11 07:40:09 guy Exp $ (LBL)
  */
 
 #ifndef lib_pcap_h
@@ -211,6 +211,8 @@ void        pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
 int    pcap_findalldevs(pcap_if_t **, char *);
 void   pcap_freealldevs(pcap_if_t *);
 
+const char *pcap_lib_version(void);
+
 /* XXX this guy lives in the bpf tree */
 u_int  bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
 int    bpf_validate(struct bpf_insn *f, int len);