diff options
Diffstat (limited to 'pcap-win32.c')
-rw-r--r-- | pcap-win32.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/pcap-win32.c b/pcap-win32.c index c1f8352c..8570396a 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -1755,3 +1755,123 @@ pcap_lookupnet(device, netp, maskp, errbuf) *netp = *maskp = 0; return (0); } + +#include "pcap_version.h" + +static const char *pcap_lib_version_string; + +#ifdef HAVE_VERSION_H +/* + * libpcap being built for Windows, as part of a WinPcap/Npcap source + * tree. Include version.h from that source tree to get the WinPcap/Npcap + * version. + * + * XXX - it'd be nice if we could somehow generate the WinPcap version number + * when building WinPcap. (It'd be nice to do so for the packet.dll version + * number as well.) + */ +#include "../../version.h" + +static const char wpcap_version_string[] = WINPCAP_VER_STRING; +static const char pcap_version_string_fmt[] = + WINPCAP_PRODUCT_NAME " version %s, based on %s"; +static const char pcap_version_string_packet_dll_fmt[] = + WINPCAP_PRODUCT_NAME " version %s (packet.dll version %s), based on %s"; + +const char * +pcap_lib_version(void) +{ + char *packet_version_string; + size_t full_pcap_version_string_len; + char *full_pcap_version_string; + + if (pcap_lib_version_string == NULL) { + /* + * Generate the version string. + */ + packet_version_string = PacketGetVersion(); + if (strcmp(wpcap_version_string, packet_version_string) == 0) { + /* + * WinPcap version string and packet.dll version + * string are the same; just report the WinPcap + * version. + */ + full_pcap_version_string_len = + (sizeof pcap_version_string_fmt - 4) + + strlen(wpcap_version_string) + + strlen(pcap_version_string); + 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, + pcap_version_string_fmt, + wpcap_version_string, + pcap_version_string); + } else { + /* + * WinPcap version string and packet.dll version + * string are different; that shouldn't be the + * case (the two libraries should come from the + * same version of WinPcap), so we report both + * versions. + */ + full_pcap_version_string_len = + (sizeof pcap_version_string_packet_dll_fmt - 6) + + strlen(wpcap_version_string) + + strlen(packet_version_string) + + strlen(pcap_version_string); + 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, + pcap_version_string_packet_dll_fmt, + wpcap_version_string, + packet_version_string, + pcap_version_string); + } + pcap_lib_version_string = full_pcap_version_string; + } + return (pcap_lib_version_string); +} + +#else /* HAVE_VERSION_H */ + +/* + * libpcap being built for Windows, not as part of a WinPcap/Npcap source + * tree. + */ +static const char pcap_version_string_packet_dll_fmt[] = + "%s (packet.dll version %s)"; +const char * +pcap_lib_version(void) +{ + char *packet_version_string; + size_t full_pcap_version_string_len; + char *full_pcap_version_string; + + if (pcap_lib_version_string == NULL) { + /* + * Generate the version string. Report the packet.dll + * version. + */ + packet_version_string = PacketGetVersion(); + full_pcap_version_string_len = + (sizeof pcap_version_string_packet_dll_fmt - 4) + + strlen(pcap_version_string) + + strlen(packet_version_string); + 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, + pcap_version_string_packet_dll_fmt, + pcap_version_string, + packet_version_string); + pcap_lib_version_string = full_pcap_version_string; + } + return (pcap_lib_version_string); +} +#endif /* HAVE_VERSION_H */ |