2 * WinPcap-specific interfaces for capturing. We load WinPcap at run
3 * time, so that we only need one Wireshark binary and one TShark binary
4 * for Windows, regardless of whether WinPcap is installed or not.
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 2001 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/strutil.h>
37 #include "capture_ifinfo.h"
38 #include "capture-pcap-util.h"
39 #include "capture-pcap-util-int.h"
40 #include "capture-wpcap.h"
42 #include <wsutil/file_util.h>
44 /* XXX - yes, I know, I should move cppmagic.h to a generic location. */
45 #include "tools/lemon/cppmagic.h"
47 #define MAX_WIN_IF_NAME_LEN 511
50 gboolean has_wpcap = FALSE;
55 * XXX - should we require at least WinPcap 3.1 both for building an
56 * for using Wireshark?
59 static char* (*p_pcap_lookupdev) (char *);
60 static void (*p_pcap_close) (pcap_t *);
61 static int (*p_pcap_stats) (pcap_t *, struct pcap_stat *);
62 static int (*p_pcap_dispatch) (pcap_t *, int, pcap_handler, guchar *);
63 static int (*p_pcap_snapshot) (pcap_t *);
64 static int (*p_pcap_datalink) (pcap_t *);
65 static int (*p_pcap_setfilter) (pcap_t *, struct bpf_program *);
66 static char* (*p_pcap_geterr) (pcap_t *);
67 static int (*p_pcap_compile) (pcap_t *, struct bpf_program *, const char *, int,
69 static int (*p_pcap_compile_nopcap) (int, int, struct bpf_program *, const char *, int,
71 static int (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *,
73 static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *);
74 static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
75 #ifdef HAVE_PCAP_OPEN_DEAD
76 static pcap_t* (*p_pcap_open_dead) (int, int);
78 static void (*p_pcap_freecode) (struct bpf_program *);
79 #ifdef HAVE_PCAP_FINDALLDEVS
80 static int (*p_pcap_findalldevs) (pcap_if_t **, char *);
81 static void (*p_pcap_freealldevs) (pcap_if_t *);
83 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
84 static int (*p_pcap_datalink_name_to_val) (const char *);
86 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
87 static const char *(*p_pcap_datalink_val_to_name) (int);
89 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
90 static const char *(*p_pcap_datalink_val_to_description) (int);
92 #ifdef HAVE_PCAP_BREAKLOOP
93 static void (*p_pcap_breakloop) (pcap_t *);
95 static const char *(*p_pcap_lib_version) (void);
96 static int (*p_pcap_setbuff) (pcap_t *, int dim);
97 static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, const u_char **pkt_data);
98 #ifdef HAVE_PCAP_REMOTE
99 static pcap_t* (*p_pcap_open) (const char *, int, int, int,
100 struct pcap_rmtauth *, char *);
101 static int (*p_pcap_findalldevs_ex) (char *, struct pcap_rmtauth *,
102 pcap_if_t **, char *);
103 static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
104 const char *, char *);
106 #ifdef HAVE_PCAP_SETSAMPLING
107 static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *);
110 #ifdef HAVE_PCAP_LIST_DATALINKS
111 static int (*p_pcap_list_datalinks)(pcap_t *, int **);
114 #ifdef HAVE_PCAP_SET_DATALINK
115 static int (*p_pcap_set_datalink)(pcap_t *, int);
118 #ifdef HAVE_PCAP_FREE_DATALINKS
119 static int (*p_pcap_free_datalinks)(int *);
122 #ifdef HAVE_BPF_IMAGE
123 static char *(*p_bpf_image) (const struct bpf_insn *, int);
132 #define SYM(x, y) { STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
138 /* These are the symbols I need or want from Wpcap */
139 static const symbol_table_t symbols[] = {
140 SYM(pcap_lookupdev, FALSE),
141 SYM(pcap_close, FALSE),
142 SYM(pcap_stats, FALSE),
143 SYM(pcap_dispatch, FALSE),
144 SYM(pcap_snapshot, FALSE),
145 SYM(pcap_datalink, FALSE),
146 SYM(pcap_setfilter, FALSE),
147 SYM(pcap_geterr, FALSE),
148 SYM(pcap_compile, FALSE),
149 SYM(pcap_compile_nopcap, FALSE),
150 SYM(pcap_lookupnet, FALSE),
151 #ifdef HAVE_PCAP_REMOTE
152 SYM(pcap_open, FALSE),
153 SYM(pcap_findalldevs_ex, FALSE),
154 SYM(pcap_createsrcstr, FALSE),
156 SYM(pcap_open_live, FALSE),
157 #ifdef HAVE_PCAP_OPEN_DEAD
158 SYM(pcap_open_dead, FALSE),
160 #ifdef HAVE_PCAP_SETSAMPLING
161 SYM(pcap_setsampling, TRUE),
163 SYM(pcap_loop, FALSE),
164 SYM(pcap_freecode, TRUE),
165 #ifdef HAVE_PCAP_FINDALLDEVS
166 SYM(pcap_findalldevs, TRUE),
167 SYM(pcap_freealldevs, TRUE),
169 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
170 SYM(pcap_datalink_name_to_val, TRUE),
172 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
173 SYM(pcap_datalink_val_to_name, TRUE),
175 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
176 SYM(pcap_datalink_val_to_description, TRUE),
178 #ifdef HAVE_PCAP_BREAKLOOP
180 * We don't try to work around the lack of this at
181 * run time; it's present in WinPcap 3.1, which is
182 * the version we build with and ship with.
184 SYM(pcap_breakloop, FALSE),
186 SYM(pcap_lib_version, TRUE),
187 SYM(pcap_setbuff, TRUE),
188 SYM(pcap_next_ex, TRUE),
189 #ifdef HAVE_PCAP_LIST_DATALINKS
190 SYM(pcap_list_datalinks, FALSE),
192 #ifdef HAVE_PCAP_SET_DATALINK
193 SYM(pcap_set_datalink, FALSE),
195 #ifdef HAVE_PCAP_FREE_DATALINKS
196 SYM(pcap_free_datalinks, TRUE),
198 #ifdef HAVE_BPF_IMAGE
199 SYM(bpf_image, FALSE),
201 { NULL, NULL, FALSE }
204 GModule *wh; /* wpcap handle */
205 const symbol_table_t *sym;
207 wh = ws_module_open("wpcap.dll", 0);
215 if (!g_module_symbol(wh, sym->name, sym->ptr)) {
218 * We don't care if it's missing; we just
224 * We require this symbol.
237 * The official list of WinPcap mirrors is at
238 * http://www.winpcap.org/misc/mirrors.htm
241 cant_load_winpcap_err(const char *app_name)
243 return g_strdup_printf(
244 "Unable to load WinPcap (wpcap.dll); %s will not be able to capture\n"
247 "In order to capture packets, WinPcap must be installed; see\n"
249 " http://www.winpcap.org/\n"
253 " http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
257 " http://winpcap.cs.pu.edu.tw/\n"
259 "for a downloadable version of WinPcap and for instructions on how to install\n"
265 pcap_lookupdev (char *a)
270 return p_pcap_lookupdev(a);
274 pcap_close(pcap_t *a)
281 pcap_stats(pcap_t *a, struct pcap_stat *b)
284 return p_pcap_stats(a, b);
288 pcap_dispatch(pcap_t *a, int b, pcap_handler c, guchar *d)
291 return p_pcap_dispatch(a, b, c, d);
295 pcap_snapshot(pcap_t *a)
298 return p_pcap_snapshot(a);
302 pcap_datalink(pcap_t *a)
305 return p_pcap_datalink(a);
308 #ifdef HAVE_PCAP_SET_DATALINK
310 pcap_set_datalink(pcap_t *p, int dlt)
313 return p_pcap_set_datalink(p, dlt);
318 pcap_setfilter(pcap_t *a, struct bpf_program *b)
321 return p_pcap_setfilter(a, b);
325 pcap_geterr(pcap_t *a)
328 return p_pcap_geterr(a);
332 pcap_compile(pcap_t *a, struct bpf_program *b, const char *c, int d,
336 return p_pcap_compile(a, b, c, d, e);
340 pcap_compile_nopcap(int a, int b, struct bpf_program *c, const char *d, int e,
344 return p_pcap_compile_nopcap(a, b, c, d, e, f);
348 pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
351 return p_pcap_lookupnet(a, b, c, d);
355 pcap_open_live(const char *a, int b, int c, int d, char *e)
358 g_snprintf(e, PCAP_ERRBUF_SIZE,
359 "unable to load WinPcap (wpcap.dll); can't open %s to capture",
363 return p_pcap_open_live(a, b, c, d, e);
366 #ifdef HAVE_PCAP_OPEN_DEAD
368 pcap_open_dead(int a, int b)
373 return p_pcap_open_dead(a, b);
377 #ifdef HAVE_BPF_IMAGE
379 bpf_image(const struct bpf_insn *a, int b)
384 return p_bpf_image(a, b);
388 #ifdef HAVE_PCAP_REMOTE
390 pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f)
393 g_snprintf(f, PCAP_ERRBUF_SIZE,
394 "unable to load WinPcap (wpcap.dll); can't open %s to capture",
398 return p_pcap_open(a, b, c, d, e, f);
402 pcap_findalldevs_ex(char *a, struct pcap_rmtauth *b, pcap_if_t **c, char *d)
405 return p_pcap_findalldevs_ex(a, b, c, d);
409 pcap_createsrcstr(char *a, int b, const char *c, const char *d, const char *e,
413 return p_pcap_createsrcstr(a, b, c, d, e, f);
417 #ifdef HAVE_PCAP_SETSAMPLING
419 pcap_setsampling(pcap_t *a)
422 if (p_pcap_setsampling != NULL) {
423 return p_pcap_setsampling(a);
430 pcap_loop(pcap_t *a, int b, pcap_handler c, guchar *d)
433 return p_pcap_loop(a, b, c, d);
437 pcap_freecode(struct bpf_program *a)
440 if(p_pcap_freecode) {
445 #ifdef HAVE_PCAP_FINDALLDEVS
447 pcap_findalldevs(pcap_if_t **a, char *b)
449 g_assert(has_wpcap && p_pcap_findalldevs != NULL);
450 return p_pcap_findalldevs(a, b);
454 pcap_freealldevs(pcap_if_t *a)
456 g_assert(has_wpcap && p_pcap_freealldevs != NULL);
457 p_pcap_freealldevs(a);
461 #if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
463 * Table of DLT_ types, names, and descriptions, for use if the version
464 * of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
465 * or "pcap_datalink_val_to_name()".
469 const char *description;
473 #define DLT_CHOICE(code, description) { #code, description, code }
474 #define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
476 static struct dlt_choice dlt_choices[] = {
477 DLT_CHOICE(DLT_NULL, "BSD loopback"),
478 DLT_CHOICE(DLT_EN10MB, "Ethernet"),
479 DLT_CHOICE(DLT_IEEE802, "Token ring"),
480 DLT_CHOICE(DLT_ARCNET, "ARCNET"),
481 DLT_CHOICE(DLT_SLIP, "SLIP"),
482 DLT_CHOICE(DLT_PPP, "PPP"),
483 DLT_CHOICE(DLT_FDDI, "FDDI"),
484 DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"),
485 DLT_CHOICE(DLT_RAW, "Raw IP"),
486 #ifdef DLT_SLIP_BSDOS
487 DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"),
490 DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
493 DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
495 #ifdef DLT_PPP_SERIAL
496 DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
499 DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
502 DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
504 #ifdef DLT_IEEE802_11
505 DLT_CHOICE(DLT_IEEE802_11, "802.11"),
508 DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
511 DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
514 DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
517 DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
520 DLT_CHOICE(DLT_LTALK, "Localtalk"),
523 DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"),
525 #ifdef DLT_PRISM_HEADER
526 DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"),
528 #ifdef DLT_IP_OVER_FC
529 DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"),
532 DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"),
534 #ifdef DLT_IEEE802_11_RADIO
535 DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"),
537 #ifdef DLT_ARCNET_LINUX
538 DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"),
540 #ifdef DLT_LINUX_IRDA
541 DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
543 #ifdef DLT_LINUX_LAPD
544 DLT_CHOICE(DLT_LINUX_LAPD, "Linux vISDN LAPD"),
547 DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"),
550 DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"),
553 DLT_CHOICE(DLT_HDLC, "Cisco HDLC"),
556 DLT_CHOICE(DLT_PPI, "Per-Packet Information"),
560 #endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */
562 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
564 pcap_datalink_name_to_val(const char *name)
570 if (p_pcap_datalink_name_to_val != NULL)
571 return p_pcap_datalink_name_to_val(name);
574 * We don't have it in WinPcap; do it ourselves.
576 for (i = 0; dlt_choices[i].name != NULL; i++) {
577 if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
579 return dlt_choices[i].dlt;
586 #ifdef HAVE_PCAP_LIST_DATALINKS
588 pcap_list_datalinks(pcap_t *p, int **ddlt)
591 return p_pcap_list_datalinks(p, ddlt);
595 #ifdef HAVE_PCAP_FREE_DATALINKS
597 pcap_free_datalinks(int *ddlt)
602 * If we don't have pcap_free_datalinks() in WinPcap,
603 * we don't free the memory - we can't use free(), as
604 * we might not have been built with the same version
605 * of the C runtime library as WinPcap was, and, if we're
606 * not, free() isn't guaranteed to work on something
607 * allocated by WinPcap.
609 if (p_pcap_free_datalinks != NULL)
610 p_pcap_free_datalinks(ddlt);
614 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
616 pcap_datalink_val_to_name(int dlt)
622 if (p_pcap_datalink_val_to_name != NULL)
623 return p_pcap_datalink_val_to_name(dlt);
626 * We don't have it in WinPcap; do it ourselves.
628 for (i = 0; dlt_choices[i].name != NULL; i++) {
629 if (dlt_choices[i].dlt == dlt)
630 return dlt_choices[i].name + sizeof("DLT_") - 1;
637 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
639 pcap_datalink_val_to_description(int dlt)
645 if (p_pcap_datalink_val_to_description != NULL)
646 return p_pcap_datalink_val_to_description(dlt);
649 * We don't have it in WinPcap; do it ourselves.
651 for (i = 0; dlt_choices[i].name != NULL; i++) {
652 if (dlt_choices[i].dlt == dlt)
653 return (dlt_choices[i].description);
660 #ifdef HAVE_PCAP_BREAKLOOP
661 void pcap_breakloop(pcap_t *a)
667 /* setbuff is win32 specific! */
668 int pcap_setbuff(pcap_t *a, int b)
671 return p_pcap_setbuff(a, b);
674 /* pcap_next_ex is available since libpcap 0.8 / WinPcap 3.0! */
675 /* (if you get a declaration warning here, try to update to at least WinPcap 3.1b4 develpack) */
676 int pcap_next_ex (pcap_t *a, struct pcap_pkthdr **b, const u_char **c)
679 return p_pcap_next_ex(a, b, c);
682 #ifdef HAVE_PCAP_REMOTE
684 get_remote_interface_list(const char *hostname, const char *port,
685 int auth_type, const char *username,
686 const char *passwd, int *err, char **err_str)
688 struct pcap_rmtauth auth;
689 char source[PCAP_BUF_SIZE];
690 char errbuf[PCAP_ERRBUF_SIZE];
693 if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
694 NULL, errbuf) == -1) {
695 *err = CANT_GET_INTERFACE_LIST;
697 *err_str = cant_get_if_list_error_message(errbuf);
701 auth.type = auth_type;
702 auth.username = g_strdup(username);
703 auth.password = g_strdup(passwd);
705 result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
706 g_free(auth.username);
707 g_free(auth.password);
714 * This will use "pcap_findalldevs()" if we have it, otherwise it'll
715 * fall back on "pcap_lookupdev()".
718 get_interface_list(int *err, char **err_str)
723 char ascii_name[MAX_WIN_IF_NAME_LEN + 1];
724 char ascii_desc[MAX_WIN_IF_NAME_LEN + 1];
726 char errbuf[PCAP_ERRBUF_SIZE];
730 * We don't have WinPcap, so we can't get a list of
733 *err = DONT_HAVE_PCAP;
734 *err_str = cant_load_winpcap_err("you");
738 #ifdef HAVE_PCAP_FINDALLDEVS
739 if (p_pcap_findalldevs != NULL)
740 return get_interface_list_findalldevs(err, err_str);
744 * In WinPcap, pcap_lookupdev is implemented by calling
745 * PacketGetAdapterNames. According to the documentation
748 * http://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
752 * On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence
753 * of bytes consisting of:
755 * a sequence of null-terminated ASCII strings (i.e., each
756 * one is terminated by a single 0 byte), giving the names
759 * an empty ASCII string (i.e., a single 0 byte);
761 * a sequence of null-terminated ASCII strings, giving the
762 * descriptions of the interfaces;
764 * an empty ASCII string.
766 * On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev
767 * returns a sequence of bytes consisting of:
769 * a sequence of null-terminated double-byte Unicode strings
770 * (i.e., each one consits of a sequence of double-byte
771 * characters, terminated by a double-byte 0), giving the
772 * names of the interfaces;
774 * an empty Unicode string (i.e., a double 0 byte);
776 * a sequence of null-terminated ASCII strings, giving the
777 * descriptions of the interfaces;
779 * an empty ASCII string.
781 * The Nth string in the first sequence is the name of the Nth
782 * adapter; the Nth string in the second sequence is the
783 * description of the Nth adapter.
786 names = (wchar_t *)pcap_lookupdev(errbuf);
795 * If names[0] is less than 256 it means the first
796 * byte is 0. This implies that we are using Unicode
799 while (*(names+desc_pos) || *(names+desc_pos-1))
801 desc_pos++; /* Step over the extra '\0' */
802 desc = (char*)(names + desc_pos); /* cast *after* addition */
804 while (names[i] != 0) {
806 * Copy the Unicode description to an ASCII
811 if (j < MAX_WIN_IF_NAME_LEN)
812 ascii_desc[j++] = *desc;
815 ascii_desc[j] = '\0';
819 * Copy the Unicode name to an ASCII string.
822 while (names[i] != 0) {
823 if (j < MAX_WIN_IF_NAME_LEN)
824 ascii_name[j++] = (char) names[i++];
826 ascii_name[j] = '\0';
828 il = g_list_append(il,
829 if_info_new(ascii_name, ascii_desc));
833 * Otherwise we are in Windows 95/98 and using ASCII
834 * (8-bit) characters.
836 win95names=(char *)names;
837 while (*(win95names+desc_pos) || *(win95names+desc_pos-1))
839 desc_pos++; /* Step over the extra '\0' */
840 desc = win95names + desc_pos;
842 while (win95names[i] != '\0') {
844 * "&win95names[i]" points to the current
845 * interface name, and "desc" points to
846 * that interface's description.
848 il = g_list_append(il,
849 if_info_new(&win95names[i], desc));
852 * Skip to the next description.
859 * Skip to the next name.
861 while (win95names[i] != 0)
870 * No interfaces found.
872 *err = NO_INTERFACES_FOUND;
881 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
882 * "get_interface_list()".
885 cant_get_if_list_error_message(const char *err_str)
888 * If the error message includes "Not enough storage is available
889 * to process this command" or "The operation completed successfully",
890 * suggest that they install a WinPcap version later than 3.0.
892 if (strstr(err_str, "Not enough storage is available to process this command") != NULL ||
893 strstr(err_str, "The operation completed successfully") != NULL) {
894 return g_strdup_printf("Can't get list of interfaces: %s\n"
895 "This might be a problem with WinPcap 3.0; you should try updating to\n"
896 "a later version of WinPcap - see the WinPcap site at www.winpcap.org",
899 return g_strdup_printf("Can't get list of interfaces: %s", err_str);
903 * Append the version of WinPcap with which we were compiled to a GString.
906 get_compiled_pcap_version(GString *str)
908 g_string_append(str, "with WinPcap (" STRINGIFY(PCAP_VERSION) ")");
912 * Append the version of WinPcap with which we we're running to a GString.
915 get_runtime_pcap_version(GString *str)
918 * On Windows, we might have been compiled with WinPcap but
919 * might not have it loaded; indicate whether we have it or
920 * not and, if we have it and we have "pcap_lib_version()",
921 * what version we have.
923 GModule *handle; /* handle returned by ws_module_open */
924 static gchar *packetVer;
928 g_string_append_printf(str, "with ");
929 if (p_pcap_lib_version != NULL)
930 g_string_append_printf(str, p_pcap_lib_version());
933 * An alternative method of obtaining the version
934 * number, by using the PacketLibraryVersion
935 * string from packet.dll.
937 * Unfortunately, in WinPcap 3.0, it returns
938 * "3.0 alpha3", even in the final version of
939 * WinPcap 3.0, so if there's a blank in the
940 * string, we strip it and everything after
941 * it from the string, so we don't misleadingly
942 * report that 3.0 alpha3 is being used when
943 * the final version is being used.
945 if (packetVer == NULL) {
946 packetVer = "version unknown";
947 handle = ws_module_open("packet.dll", 0);
948 if (handle != NULL) {
949 if (g_module_symbol(handle,
950 "PacketLibraryVersion",
951 (gpointer*)&packetVer)) {
952 packetVer = g_strdup(packetVer);
953 blankp = strchr(packetVer, ' ');
957 packetVer = "version unknown";
959 g_module_close(handle);
962 g_string_append_printf(str, "WinPcap (%s)", packetVer);
965 g_string_append(str, "without WinPcap");
968 #else /* HAVE_LIBPCAP */
977 * Append an indication that we were not compiled with WinPcap
981 get_compiled_pcap_version(GString *str)
983 g_string_append(str, "without WinPcap");
987 * Don't append anything, as we weren't even compiled to use WinPcap.
990 get_runtime_pcap_version(GString *str _U_)
994 #endif /* HAVE_LIBPCAP */