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.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2001 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/strutil.h>
33 #include <capchild/capture_ifinfo.h>
34 #include "capture-pcap-util.h"
35 #include "capture-pcap-util-int.h"
36 #include "capture-wpcap.h"
38 #include <wsutil/file_util.h>
40 /* XXX - yes, I know, I should move cppmagic.h to a generic location. */
41 #include "tools/lemon/cppmagic.h"
43 #define MAX_WIN_IF_NAME_LEN 511
46 gboolean has_wpcap = FALSE;
51 * XXX - should we require at least WinPcap 3.1 both for building an
52 * for using Wireshark?
55 static char* (*p_pcap_lookupdev) (char *);
56 static void (*p_pcap_close) (pcap_t *);
57 static int (*p_pcap_stats) (pcap_t *, struct pcap_stat *);
58 static int (*p_pcap_dispatch) (pcap_t *, int, pcap_handler, guchar *);
59 static int (*p_pcap_snapshot) (pcap_t *);
60 static int (*p_pcap_datalink) (pcap_t *);
61 static int (*p_pcap_setfilter) (pcap_t *, struct bpf_program *);
62 static char* (*p_pcap_geterr) (pcap_t *);
63 static int (*p_pcap_compile) (pcap_t *, struct bpf_program *, const char *, int,
65 static int (*p_pcap_compile_nopcap) (int, int, struct bpf_program *, const char *, int,
67 static int (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *,
69 static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *);
70 static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
71 #ifdef HAVE_PCAP_OPEN_DEAD
72 static pcap_t* (*p_pcap_open_dead) (int, int);
74 static void (*p_pcap_freecode) (struct bpf_program *);
75 #ifdef HAVE_PCAP_FINDALLDEVS
76 static int (*p_pcap_findalldevs) (pcap_if_t **, char *);
77 static void (*p_pcap_freealldevs) (pcap_if_t *);
79 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
80 static int (*p_pcap_datalink_name_to_val) (const char *);
82 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
83 static const char *(*p_pcap_datalink_val_to_name) (int);
85 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
86 static const char *(*p_pcap_datalink_val_to_description) (int);
88 #ifdef HAVE_PCAP_BREAKLOOP
89 static void (*p_pcap_breakloop) (pcap_t *);
91 static const char *(*p_pcap_lib_version) (void);
92 static int (*p_pcap_setbuff) (pcap_t *, int dim);
93 static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, const u_char **pkt_data);
94 #ifdef HAVE_PCAP_REMOTE
95 static pcap_t* (*p_pcap_open) (const char *, int, int, int,
96 struct pcap_rmtauth *, char *);
97 static int (*p_pcap_findalldevs_ex) (char *, struct pcap_rmtauth *,
98 pcap_if_t **, char *);
99 static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
100 const char *, char *);
102 #ifdef HAVE_PCAP_SETSAMPLING
103 static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *);
106 #ifdef HAVE_PCAP_LIST_DATALINKS
107 static int (*p_pcap_list_datalinks)(pcap_t *, int **);
110 #ifdef HAVE_PCAP_SET_DATALINK
111 static int (*p_pcap_set_datalink)(pcap_t *, int);
114 #ifdef HAVE_PCAP_FREE_DATALINKS
115 static int (*p_pcap_free_datalinks)(int *);
118 #ifdef HAVE_BPF_IMAGE
119 static char *(*p_bpf_image) (const struct bpf_insn *, int);
128 #define SYM(x, y) { G_STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
134 /* These are the symbols I need or want from Wpcap */
135 static const symbol_table_t symbols[] = {
136 SYM(pcap_lookupdev, FALSE),
137 SYM(pcap_close, FALSE),
138 SYM(pcap_stats, FALSE),
139 SYM(pcap_dispatch, FALSE),
140 SYM(pcap_snapshot, FALSE),
141 SYM(pcap_datalink, FALSE),
142 SYM(pcap_setfilter, FALSE),
143 SYM(pcap_geterr, FALSE),
144 SYM(pcap_compile, FALSE),
145 SYM(pcap_compile_nopcap, FALSE),
146 SYM(pcap_lookupnet, FALSE),
147 #ifdef HAVE_PCAP_REMOTE
148 SYM(pcap_open, FALSE),
149 SYM(pcap_findalldevs_ex, FALSE),
150 SYM(pcap_createsrcstr, FALSE),
152 SYM(pcap_open_live, FALSE),
153 #ifdef HAVE_PCAP_OPEN_DEAD
154 SYM(pcap_open_dead, FALSE),
156 #ifdef HAVE_PCAP_SETSAMPLING
157 SYM(pcap_setsampling, TRUE),
159 SYM(pcap_loop, FALSE),
160 SYM(pcap_freecode, TRUE),
161 #ifdef HAVE_PCAP_FINDALLDEVS
162 SYM(pcap_findalldevs, TRUE),
163 SYM(pcap_freealldevs, TRUE),
165 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
166 SYM(pcap_datalink_name_to_val, TRUE),
168 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
169 SYM(pcap_datalink_val_to_name, TRUE),
171 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
172 SYM(pcap_datalink_val_to_description, TRUE),
174 #ifdef HAVE_PCAP_BREAKLOOP
176 * We don't try to work around the lack of this at
177 * run time; it's present in WinPcap 3.1, which is
178 * the version we build with and ship with.
180 SYM(pcap_breakloop, FALSE),
182 SYM(pcap_lib_version, TRUE),
183 SYM(pcap_setbuff, TRUE),
184 SYM(pcap_next_ex, TRUE),
185 #ifdef HAVE_PCAP_LIST_DATALINKS
186 SYM(pcap_list_datalinks, FALSE),
188 #ifdef HAVE_PCAP_SET_DATALINK
189 SYM(pcap_set_datalink, FALSE),
191 #ifdef HAVE_PCAP_FREE_DATALINKS
192 SYM(pcap_free_datalinks, TRUE),
194 #ifdef HAVE_BPF_IMAGE
195 SYM(bpf_image, FALSE),
197 { NULL, NULL, FALSE }
200 GModule *wh; /* wpcap handle */
201 const symbol_table_t *sym;
203 wh = ws_module_open("wpcap.dll", 0);
211 if (!g_module_symbol(wh, sym->name, sym->ptr)) {
214 * We don't care if it's missing; we just
220 * We require this symbol.
233 * The official list of WinPcap mirrors is at
234 * http://www.winpcap.org/misc/mirrors.htm
237 cant_load_winpcap_err(const char *app_name)
239 return g_strdup_printf(
240 "Unable to load WinPcap (wpcap.dll); %s will not be able to capture\n"
243 "In order to capture packets, WinPcap must be installed; see\n"
245 " http://www.winpcap.org/\n"
249 " http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
253 " http://winpcap.cs.pu.edu.tw/\n"
255 "for a downloadable version of WinPcap and for instructions on how to install\n"
261 pcap_lookupdev (char *a)
266 return p_pcap_lookupdev(a);
270 pcap_close(pcap_t *a)
277 pcap_stats(pcap_t *a, struct pcap_stat *b)
280 return p_pcap_stats(a, b);
284 pcap_dispatch(pcap_t *a, int b, pcap_handler c, guchar *d)
287 return p_pcap_dispatch(a, b, c, d);
291 pcap_snapshot(pcap_t *a)
294 return p_pcap_snapshot(a);
298 pcap_datalink(pcap_t *a)
301 return p_pcap_datalink(a);
304 #ifdef HAVE_PCAP_SET_DATALINK
306 pcap_set_datalink(pcap_t *p, int dlt)
309 return p_pcap_set_datalink(p, dlt);
314 pcap_setfilter(pcap_t *a, struct bpf_program *b)
317 return p_pcap_setfilter(a, b);
321 pcap_geterr(pcap_t *a)
324 return p_pcap_geterr(a);
328 pcap_compile(pcap_t *a, struct bpf_program *b, const char *c, int d,
332 return p_pcap_compile(a, b, c, d, e);
336 pcap_compile_nopcap(int a, int b, struct bpf_program *c, const char *d, int e,
340 return p_pcap_compile_nopcap(a, b, c, d, e, f);
344 pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
347 return p_pcap_lookupnet(a, b, c, d);
351 pcap_open_live(const char *a, int b, int c, int d, char *e)
354 g_snprintf(e, PCAP_ERRBUF_SIZE,
355 "unable to load WinPcap (wpcap.dll); can't open %s to capture",
359 return p_pcap_open_live(a, b, c, d, e);
362 #ifdef HAVE_PCAP_OPEN_DEAD
364 pcap_open_dead(int a, int b)
369 return p_pcap_open_dead(a, b);
373 #ifdef HAVE_BPF_IMAGE
375 bpf_image(const struct bpf_insn *a, int b)
380 return p_bpf_image(a, b);
384 #ifdef HAVE_PCAP_REMOTE
386 pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f)
389 g_snprintf(f, PCAP_ERRBUF_SIZE,
390 "unable to load WinPcap (wpcap.dll); can't open %s to capture",
394 return p_pcap_open(a, b, c, d, e, f);
398 pcap_findalldevs_ex(char *a, struct pcap_rmtauth *b, pcap_if_t **c, char *d)
401 return p_pcap_findalldevs_ex(a, b, c, d);
405 pcap_createsrcstr(char *a, int b, const char *c, const char *d, const char *e,
409 return p_pcap_createsrcstr(a, b, c, d, e, f);
413 #ifdef HAVE_PCAP_SETSAMPLING
415 pcap_setsampling(pcap_t *a)
418 if (p_pcap_setsampling != NULL) {
419 return p_pcap_setsampling(a);
426 pcap_loop(pcap_t *a, int b, pcap_handler c, guchar *d)
429 return p_pcap_loop(a, b, c, d);
433 pcap_freecode(struct bpf_program *a)
436 if(p_pcap_freecode) {
441 #ifdef HAVE_PCAP_FINDALLDEVS
443 pcap_findalldevs(pcap_if_t **a, char *b)
445 g_assert(has_wpcap && p_pcap_findalldevs != NULL);
446 return p_pcap_findalldevs(a, b);
450 pcap_freealldevs(pcap_if_t *a)
452 g_assert(has_wpcap && p_pcap_freealldevs != NULL);
453 p_pcap_freealldevs(a);
457 #if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
459 * Table of DLT_ types, names, and descriptions, for use if the version
460 * of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
461 * or "pcap_datalink_val_to_name()".
465 const char *description;
469 #define DLT_CHOICE(code, description) { #code, description, code }
470 #define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
472 static struct dlt_choice dlt_choices[] = {
473 DLT_CHOICE(DLT_NULL, "BSD loopback"),
474 DLT_CHOICE(DLT_EN10MB, "Ethernet"),
475 DLT_CHOICE(DLT_IEEE802, "Token ring"),
476 DLT_CHOICE(DLT_ARCNET, "ARCNET"),
477 DLT_CHOICE(DLT_SLIP, "SLIP"),
478 DLT_CHOICE(DLT_PPP, "PPP"),
479 DLT_CHOICE(DLT_FDDI, "FDDI"),
480 DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"),
481 DLT_CHOICE(DLT_RAW, "Raw IP"),
482 #ifdef DLT_SLIP_BSDOS
483 DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"),
486 DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
489 DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
491 #ifdef DLT_PPP_SERIAL
492 DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
495 DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
498 DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
500 #ifdef DLT_IEEE802_11
501 DLT_CHOICE(DLT_IEEE802_11, "802.11"),
504 DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
507 DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
510 DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
513 DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
516 DLT_CHOICE(DLT_LTALK, "Localtalk"),
519 DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"),
521 #ifdef DLT_PRISM_HEADER
522 DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"),
524 #ifdef DLT_IP_OVER_FC
525 DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"),
528 DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"),
530 #ifdef DLT_IEEE802_11_RADIO
531 DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"),
533 #ifdef DLT_ARCNET_LINUX
534 DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"),
536 #ifdef DLT_LINUX_IRDA
537 DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
539 #ifdef DLT_LINUX_LAPD
540 DLT_CHOICE(DLT_LINUX_LAPD, "Linux vISDN LAPD"),
543 DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"),
546 DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"),
549 DLT_CHOICE(DLT_HDLC, "Cisco HDLC"),
552 DLT_CHOICE(DLT_PPI, "Per-Packet Information"),
556 #endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */
558 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
560 pcap_datalink_name_to_val(const char *name)
566 if (p_pcap_datalink_name_to_val != NULL)
567 return p_pcap_datalink_name_to_val(name);
570 * We don't have it in WinPcap; do it ourselves.
572 for (i = 0; dlt_choices[i].name != NULL; i++) {
573 if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
575 return dlt_choices[i].dlt;
582 #ifdef HAVE_PCAP_LIST_DATALINKS
584 pcap_list_datalinks(pcap_t *p, int **ddlt)
587 return p_pcap_list_datalinks(p, ddlt);
591 #ifdef HAVE_PCAP_FREE_DATALINKS
593 pcap_free_datalinks(int *ddlt)
598 * If we don't have pcap_free_datalinks() in WinPcap,
599 * we don't free the memory - we can't use free(), as
600 * we might not have been built with the same version
601 * of the C runtime library as WinPcap was, and, if we're
602 * not, free() isn't guaranteed to work on something
603 * allocated by WinPcap.
605 if (p_pcap_free_datalinks != NULL)
606 p_pcap_free_datalinks(ddlt);
610 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
612 pcap_datalink_val_to_name(int dlt)
618 if (p_pcap_datalink_val_to_name != NULL)
619 return p_pcap_datalink_val_to_name(dlt);
622 * We don't have it in WinPcap; do it ourselves.
624 for (i = 0; dlt_choices[i].name != NULL; i++) {
625 if (dlt_choices[i].dlt == dlt)
626 return dlt_choices[i].name + sizeof("DLT_") - 1;
633 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
635 pcap_datalink_val_to_description(int dlt)
641 if (p_pcap_datalink_val_to_description != NULL)
642 return p_pcap_datalink_val_to_description(dlt);
645 * We don't have it in WinPcap; do it ourselves.
647 for (i = 0; dlt_choices[i].name != NULL; i++) {
648 if (dlt_choices[i].dlt == dlt)
649 return (dlt_choices[i].description);
656 #ifdef HAVE_PCAP_BREAKLOOP
657 void pcap_breakloop(pcap_t *a)
663 /* setbuff is win32 specific! */
664 int pcap_setbuff(pcap_t *a, int b)
667 return p_pcap_setbuff(a, b);
670 /* pcap_next_ex is available since libpcap 0.8 / WinPcap 3.0! */
671 /* (if you get a declaration warning here, try to update to at least WinPcap 3.1b4 develpack) */
672 int pcap_next_ex (pcap_t *a, struct pcap_pkthdr **b, const u_char **c)
675 return p_pcap_next_ex(a, b, c);
678 #ifdef HAVE_PCAP_REMOTE
680 get_remote_interface_list(const char *hostname, const char *port,
681 int auth_type, const char *username,
682 const char *passwd, int *err, char **err_str)
684 struct pcap_rmtauth auth;
685 char source[PCAP_BUF_SIZE];
686 char errbuf[PCAP_ERRBUF_SIZE];
689 if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
690 NULL, errbuf) == -1) {
691 *err = CANT_GET_INTERFACE_LIST;
693 *err_str = cant_get_if_list_error_message(errbuf);
697 auth.type = auth_type;
698 auth.username = g_strdup(username);
699 auth.password = g_strdup(passwd);
701 result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
702 g_free(auth.username);
703 g_free(auth.password);
710 * This will use "pcap_findalldevs()" if we have it, otherwise it'll
711 * fall back on "pcap_lookupdev()".
714 get_interface_list(int *err, char **err_str)
719 char ascii_name[MAX_WIN_IF_NAME_LEN + 1];
720 char ascii_desc[MAX_WIN_IF_NAME_LEN + 1];
722 char errbuf[PCAP_ERRBUF_SIZE];
726 * We don't have WinPcap, so we can't get a list of
729 *err = DONT_HAVE_PCAP;
730 *err_str = cant_load_winpcap_err("you");
734 #ifdef HAVE_PCAP_FINDALLDEVS
735 if (p_pcap_findalldevs != NULL)
736 return get_interface_list_findalldevs(err, err_str);
740 * In WinPcap, pcap_lookupdev is implemented by calling
741 * PacketGetAdapterNames. According to the documentation
744 * http://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
748 * On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence
749 * of bytes consisting of:
751 * a sequence of null-terminated ASCII strings (i.e., each
752 * one is terminated by a single 0 byte), giving the names
755 * an empty ASCII string (i.e., a single 0 byte);
757 * a sequence of null-terminated ASCII strings, giving the
758 * descriptions of the interfaces;
760 * an empty ASCII string.
762 * On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev
763 * returns a sequence of bytes consisting of:
765 * a sequence of null-terminated double-byte Unicode strings
766 * (i.e., each one consits of a sequence of double-byte
767 * characters, terminated by a double-byte 0), giving the
768 * names of the interfaces;
770 * an empty Unicode string (i.e., a double 0 byte);
772 * a sequence of null-terminated ASCII strings, giving the
773 * descriptions of the interfaces;
775 * an empty ASCII string.
777 * The Nth string in the first sequence is the name of the Nth
778 * adapter; the Nth string in the second sequence is the
779 * description of the Nth adapter.
782 names = (wchar_t *)pcap_lookupdev(errbuf);
791 * If names[0] is less than 256 it means the first
792 * byte is 0. This implies that we are using Unicode
795 while (*(names+desc_pos) || *(names+desc_pos-1))
797 desc_pos++; /* Step over the extra '\0' */
798 desc = (char*)(names + desc_pos); /* cast *after* addition */
800 while (names[i] != 0) {
802 * Copy the Unicode description to an ASCII
807 if (j < MAX_WIN_IF_NAME_LEN)
808 ascii_desc[j++] = *desc;
811 ascii_desc[j] = '\0';
815 * Copy the Unicode name to an ASCII string.
818 while (names[i] != 0) {
819 if (j < MAX_WIN_IF_NAME_LEN)
820 ascii_name[j++] = (char) names[i++];
822 ascii_name[j] = '\0';
824 il = g_list_append(il,
825 if_info_new(ascii_name, ascii_desc, FALSE));
829 * Otherwise we are in Windows 95/98 and using ASCII
830 * (8-bit) characters.
832 win95names=(char *)names;
833 while (*(win95names+desc_pos) || *(win95names+desc_pos-1))
835 desc_pos++; /* Step over the extra '\0' */
836 desc = win95names + desc_pos;
838 while (win95names[i] != '\0') {
840 * "&win95names[i]" points to the current
841 * interface name, and "desc" points to
842 * that interface's description.
844 il = g_list_append(il,
845 if_info_new(&win95names[i], desc, FALSE));
848 * Skip to the next description.
855 * Skip to the next name.
857 while (win95names[i] != 0)
866 * No interfaces found.
868 *err = NO_INTERFACES_FOUND;
877 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
878 * "get_interface_list()".
881 cant_get_if_list_error_message(const char *err_str)
884 * If the error message includes "Not enough storage is available
885 * to process this command" or "The operation completed successfully",
886 * suggest that they install a WinPcap version later than 3.0.
888 if (strstr(err_str, "Not enough storage is available to process this command") != NULL ||
889 strstr(err_str, "The operation completed successfully") != NULL) {
890 return g_strdup_printf("Can't get list of interfaces: %s\n"
891 "This might be a problem with WinPcap 3.0; you should try updating to\n"
892 "a later version of WinPcap - see the WinPcap site at www.winpcap.org",
895 return g_strdup_printf("Can't get list of interfaces: %s", err_str);
899 * Append the version of WinPcap with which we were compiled to a GString.
902 get_compiled_pcap_version(GString *str)
904 g_string_append(str, "with WinPcap (" G_STRINGIFY(WINPCAP_VERSION) ")");
908 * Append the version of WinPcap with which we we're running to a GString.
911 get_runtime_pcap_version(GString *str)
914 * On Windows, we might have been compiled with WinPcap but
915 * might not have it loaded; indicate whether we have it or
916 * not and, if we have it and we have "pcap_lib_version()",
917 * what version we have.
919 GModule *handle; /* handle returned by ws_module_open */
920 static gchar *packetVer;
924 g_string_append_printf(str, "with ");
925 if (p_pcap_lib_version != NULL)
926 g_string_append_printf(str, p_pcap_lib_version());
929 * An alternative method of obtaining the version
930 * number, by using the PacketLibraryVersion
931 * string from packet.dll.
933 * Unfortunately, in WinPcap 3.0, it returns
934 * "3.0 alpha3", even in the final version of
935 * WinPcap 3.0, so if there's a blank in the
936 * string, we strip it and everything after
937 * it from the string, so we don't misleadingly
938 * report that 3.0 alpha3 is being used when
939 * the final version is being used.
941 if (packetVer == NULL) {
942 packetVer = "version unknown";
943 handle = ws_module_open("packet.dll", 0);
944 if (handle != NULL) {
945 if (g_module_symbol(handle,
946 "PacketLibraryVersion",
947 (gpointer*)&packetVer)) {
948 packetVer = g_strdup(packetVer);
949 blankp = strchr(packetVer, ' ');
953 packetVer = "version unknown";
955 g_module_close(handle);
958 g_string_append_printf(str, "WinPcap (%s)", packetVer);
961 g_string_append(str, "without WinPcap");
964 #else /* HAVE_LIBPCAP */
973 * Append an indication that we were not compiled with WinPcap
977 get_compiled_pcap_version(GString *str)
979 g_string_append(str, "without WinPcap");
983 * Don't append anything, as we weren't even compiled to use WinPcap.
986 get_runtime_pcap_version(GString *str _U_)
990 #endif /* HAVE_LIBPCAP */