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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/strutil.h>
35 #include "capture_ifinfo.h"
36 #include "capture-pcap-util.h"
37 #include "capture-pcap-util-int.h"
38 #include "capture-wpcap.h"
40 #include <wsutil/file_util.h>
42 /* XXX - yes, I know, I should move cppmagic.h to a generic location. */
43 #include "tools/lemon/cppmagic.h"
45 #define MAX_WIN_IF_NAME_LEN 511
48 gboolean has_wpcap
= FALSE
;
53 * XXX - should we require at least WinPcap 3.1 both for building an
54 * for using Wireshark?
57 static char* (*p_pcap_lookupdev
) (char *);
58 static void (*p_pcap_close
) (pcap_t
*);
59 static int (*p_pcap_stats
) (pcap_t
*, struct pcap_stat
*);
60 static int (*p_pcap_dispatch
) (pcap_t
*, int, pcap_handler
, guchar
*);
61 static int (*p_pcap_snapshot
) (pcap_t
*);
62 static int (*p_pcap_datalink
) (pcap_t
*);
63 static int (*p_pcap_setfilter
) (pcap_t
*, struct bpf_program
*);
64 static char* (*p_pcap_geterr
) (pcap_t
*);
65 static int (*p_pcap_compile
) (pcap_t
*, struct bpf_program
*, const char *, int,
67 static int (*p_pcap_compile_nopcap
) (int, int, struct bpf_program
*, const char *, int,
69 static int (*p_pcap_lookupnet
) (const char *, bpf_u_int32
*, bpf_u_int32
*,
71 static pcap_t
* (*p_pcap_open_live
) (const char *, int, int, int, char *);
72 static int (*p_pcap_loop
) (pcap_t
*, int, pcap_handler
, guchar
*);
73 #ifdef HAVE_PCAP_OPEN_DEAD
74 static pcap_t
* (*p_pcap_open_dead
) (int, int);
76 static void (*p_pcap_freecode
) (struct bpf_program
*);
77 #ifdef HAVE_PCAP_FINDALLDEVS
78 static int (*p_pcap_findalldevs
) (pcap_if_t
**, char *);
79 static void (*p_pcap_freealldevs
) (pcap_if_t
*);
81 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
82 static int (*p_pcap_datalink_name_to_val
) (const char *);
84 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
85 static const char *(*p_pcap_datalink_val_to_name
) (int);
87 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
88 static const char *(*p_pcap_datalink_val_to_description
) (int);
90 #ifdef HAVE_PCAP_BREAKLOOP
91 static void (*p_pcap_breakloop
) (pcap_t
*);
93 static const char *(*p_pcap_lib_version
) (void);
94 static int (*p_pcap_setbuff
) (pcap_t
*, int dim
);
95 static int (*p_pcap_next_ex
) (pcap_t
*, struct pcap_pkthdr
**pkt_header
, const u_char
**pkt_data
);
96 #ifdef HAVE_PCAP_REMOTE
97 static pcap_t
* (*p_pcap_open
) (const char *, int, int, int,
98 struct pcap_rmtauth
*, char *);
99 static int (*p_pcap_findalldevs_ex
) (char *, struct pcap_rmtauth
*,
100 pcap_if_t
**, char *);
101 static int (*p_pcap_createsrcstr
) (char *, int, const char *, const char *,
102 const char *, char *);
104 #ifdef HAVE_PCAP_SETSAMPLING
105 static struct pcap_samp
* (*p_pcap_setsampling
)(pcap_t
*);
108 #ifdef HAVE_PCAP_LIST_DATALINKS
109 static int (*p_pcap_list_datalinks
)(pcap_t
*, int **);
112 #ifdef HAVE_PCAP_SET_DATALINK
113 static int (*p_pcap_set_datalink
)(pcap_t
*, int);
116 #ifdef HAVE_PCAP_FREE_DATALINKS
117 static int (*p_pcap_free_datalinks
)(int *);
120 #ifdef HAVE_BPF_IMAGE
121 static char *(*p_bpf_image
) (const struct bpf_insn
*, int);
130 #define SYM(x, y) { G_STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
136 /* These are the symbols I need or want from Wpcap */
137 static const symbol_table_t symbols
[] = {
138 SYM(pcap_lookupdev
, FALSE
),
139 SYM(pcap_close
, FALSE
),
140 SYM(pcap_stats
, FALSE
),
141 SYM(pcap_dispatch
, FALSE
),
142 SYM(pcap_snapshot
, FALSE
),
143 SYM(pcap_datalink
, FALSE
),
144 SYM(pcap_setfilter
, FALSE
),
145 SYM(pcap_geterr
, FALSE
),
146 SYM(pcap_compile
, FALSE
),
147 SYM(pcap_compile_nopcap
, FALSE
),
148 SYM(pcap_lookupnet
, FALSE
),
149 #ifdef HAVE_PCAP_REMOTE
150 SYM(pcap_open
, FALSE
),
151 SYM(pcap_findalldevs_ex
, FALSE
),
152 SYM(pcap_createsrcstr
, FALSE
),
154 SYM(pcap_open_live
, FALSE
),
155 #ifdef HAVE_PCAP_OPEN_DEAD
156 SYM(pcap_open_dead
, FALSE
),
158 #ifdef HAVE_PCAP_SETSAMPLING
159 SYM(pcap_setsampling
, TRUE
),
161 SYM(pcap_loop
, FALSE
),
162 SYM(pcap_freecode
, TRUE
),
163 #ifdef HAVE_PCAP_FINDALLDEVS
164 SYM(pcap_findalldevs
, TRUE
),
165 SYM(pcap_freealldevs
, TRUE
),
167 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
168 SYM(pcap_datalink_name_to_val
, TRUE
),
170 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
171 SYM(pcap_datalink_val_to_name
, TRUE
),
173 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
174 SYM(pcap_datalink_val_to_description
, TRUE
),
176 #ifdef HAVE_PCAP_BREAKLOOP
178 * We don't try to work around the lack of this at
179 * run time; it's present in WinPcap 3.1, which is
180 * the version we build with and ship with.
182 SYM(pcap_breakloop
, FALSE
),
184 SYM(pcap_lib_version
, TRUE
),
185 SYM(pcap_setbuff
, TRUE
),
186 SYM(pcap_next_ex
, TRUE
),
187 #ifdef HAVE_PCAP_LIST_DATALINKS
188 SYM(pcap_list_datalinks
, FALSE
),
190 #ifdef HAVE_PCAP_SET_DATALINK
191 SYM(pcap_set_datalink
, FALSE
),
193 #ifdef HAVE_PCAP_FREE_DATALINKS
194 SYM(pcap_free_datalinks
, TRUE
),
196 #ifdef HAVE_BPF_IMAGE
197 SYM(bpf_image
, FALSE
),
199 { NULL
, NULL
, FALSE
}
202 GModule
*wh
; /* wpcap handle */
203 const symbol_table_t
*sym
;
205 wh
= ws_module_open("wpcap.dll", 0);
213 if (!g_module_symbol(wh
, sym
->name
, sym
->ptr
)) {
216 * We don't care if it's missing; we just
222 * We require this symbol.
235 * The official list of WinPcap mirrors is at
236 * http://www.winpcap.org/misc/mirrors.htm
239 cant_load_winpcap_err(const char *app_name
)
241 return g_strdup_printf(
242 "Unable to load WinPcap (wpcap.dll); %s will not be able to capture\n"
245 "In order to capture packets, WinPcap must be installed; see\n"
247 " http://www.winpcap.org/\n"
251 " http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
255 " http://winpcap.cs.pu.edu.tw/\n"
257 "for a downloadable version of WinPcap and for instructions on how to install\n"
263 pcap_lookupdev (char *a
)
268 return p_pcap_lookupdev(a
);
272 pcap_close(pcap_t
*a
)
279 pcap_stats(pcap_t
*a
, struct pcap_stat
*b
)
282 return p_pcap_stats(a
, b
);
286 pcap_dispatch(pcap_t
*a
, int b
, pcap_handler c
, guchar
*d
)
289 return p_pcap_dispatch(a
, b
, c
, d
);
293 pcap_snapshot(pcap_t
*a
)
296 return p_pcap_snapshot(a
);
300 pcap_datalink(pcap_t
*a
)
303 return p_pcap_datalink(a
);
306 #ifdef HAVE_PCAP_SET_DATALINK
308 pcap_set_datalink(pcap_t
*p
, int dlt
)
311 return p_pcap_set_datalink(p
, dlt
);
316 pcap_setfilter(pcap_t
*a
, struct bpf_program
*b
)
319 return p_pcap_setfilter(a
, b
);
323 pcap_geterr(pcap_t
*a
)
326 return p_pcap_geterr(a
);
330 pcap_compile(pcap_t
*a
, struct bpf_program
*b
, const char *c
, int d
,
334 return p_pcap_compile(a
, b
, c
, d
, e
);
338 pcap_compile_nopcap(int a
, int b
, struct bpf_program
*c
, const char *d
, int e
,
342 return p_pcap_compile_nopcap(a
, b
, c
, d
, e
, f
);
346 pcap_lookupnet(const char *a
, bpf_u_int32
*b
, bpf_u_int32
*c
, char *d
)
349 return p_pcap_lookupnet(a
, b
, c
, d
);
353 pcap_open_live(const char *a
, int b
, int c
, int d
, char *e
)
356 g_snprintf(e
, PCAP_ERRBUF_SIZE
,
357 "unable to load WinPcap (wpcap.dll); can't open %s to capture",
361 return p_pcap_open_live(a
, b
, c
, d
, e
);
364 #ifdef HAVE_PCAP_OPEN_DEAD
366 pcap_open_dead(int a
, int b
)
371 return p_pcap_open_dead(a
, b
);
375 #ifdef HAVE_BPF_IMAGE
377 bpf_image(const struct bpf_insn
*a
, int b
)
382 return p_bpf_image(a
, b
);
386 #ifdef HAVE_PCAP_REMOTE
388 pcap_open(const char *a
, int b
, int c
, int d
, struct pcap_rmtauth
*e
, char *f
)
391 g_snprintf(f
, PCAP_ERRBUF_SIZE
,
392 "unable to load WinPcap (wpcap.dll); can't open %s to capture",
396 return p_pcap_open(a
, b
, c
, d
, e
, f
);
400 pcap_findalldevs_ex(char *a
, struct pcap_rmtauth
*b
, pcap_if_t
**c
, char *d
)
403 return p_pcap_findalldevs_ex(a
, b
, c
, d
);
407 pcap_createsrcstr(char *a
, int b
, const char *c
, const char *d
, const char *e
,
411 return p_pcap_createsrcstr(a
, b
, c
, d
, e
, f
);
415 #ifdef HAVE_PCAP_SETSAMPLING
417 pcap_setsampling(pcap_t
*a
)
420 if (p_pcap_setsampling
!= NULL
) {
421 return p_pcap_setsampling(a
);
428 pcap_loop(pcap_t
*a
, int b
, pcap_handler c
, guchar
*d
)
431 return p_pcap_loop(a
, b
, c
, d
);
435 pcap_freecode(struct bpf_program
*a
)
438 if(p_pcap_freecode
) {
443 #ifdef HAVE_PCAP_FINDALLDEVS
445 pcap_findalldevs(pcap_if_t
**a
, char *b
)
447 g_assert(has_wpcap
&& p_pcap_findalldevs
!= NULL
);
448 return p_pcap_findalldevs(a
, b
);
452 pcap_freealldevs(pcap_if_t
*a
)
454 g_assert(has_wpcap
&& p_pcap_freealldevs
!= NULL
);
455 p_pcap_freealldevs(a
);
459 #if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
461 * Table of DLT_ types, names, and descriptions, for use if the version
462 * of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
463 * or "pcap_datalink_val_to_name()".
467 const char *description
;
471 #define DLT_CHOICE(code, description) { #code, description, code }
472 #define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
474 static struct dlt_choice dlt_choices
[] = {
475 DLT_CHOICE(DLT_NULL
, "BSD loopback"),
476 DLT_CHOICE(DLT_EN10MB
, "Ethernet"),
477 DLT_CHOICE(DLT_IEEE802
, "Token ring"),
478 DLT_CHOICE(DLT_ARCNET
, "ARCNET"),
479 DLT_CHOICE(DLT_SLIP
, "SLIP"),
480 DLT_CHOICE(DLT_PPP
, "PPP"),
481 DLT_CHOICE(DLT_FDDI
, "FDDI"),
482 DLT_CHOICE(DLT_ATM_RFC1483
, "RFC 1483 IP-over-ATM"),
483 DLT_CHOICE(DLT_RAW
, "Raw IP"),
484 #ifdef DLT_SLIP_BSDOS
485 DLT_CHOICE(DLT_SLIP_BSDOS
, "BSD/OS SLIP"),
488 DLT_CHOICE(DLT_PPP_BSDOS
, "BSD/OS PPP"),
491 DLT_CHOICE(DLT_ATM_CLIP
, "Linux Classical IP-over-ATM"),
493 #ifdef DLT_PPP_SERIAL
494 DLT_CHOICE(DLT_PPP_SERIAL
, "PPP over serial"),
497 DLT_CHOICE(DLT_PPP_ETHER
, "PPPoE"),
500 DLT_CHOICE(DLT_C_HDLC
, "Cisco HDLC"),
502 #ifdef DLT_IEEE802_11
503 DLT_CHOICE(DLT_IEEE802_11
, "802.11"),
506 DLT_CHOICE(DLT_FRELAY
, "Frame Relay"),
509 DLT_CHOICE(DLT_LOOP
, "OpenBSD loopback"),
512 DLT_CHOICE(DLT_ENC
, "OpenBSD encapsulated IP"),
515 DLT_CHOICE(DLT_LINUX_SLL
, "Linux cooked"),
518 DLT_CHOICE(DLT_LTALK
, "Localtalk"),
521 DLT_CHOICE(DLT_PFLOG
, "OpenBSD pflog file"),
523 #ifdef DLT_PRISM_HEADER
524 DLT_CHOICE(DLT_PRISM_HEADER
, "802.11 plus Prism header"),
526 #ifdef DLT_IP_OVER_FC
527 DLT_CHOICE(DLT_IP_OVER_FC
, "RFC 2625 IP-over-Fibre Channel"),
530 DLT_CHOICE(DLT_SUNATM
, "Sun raw ATM"),
532 #ifdef DLT_IEEE802_11_RADIO
533 DLT_CHOICE(DLT_IEEE802_11_RADIO
, "802.11 plus radio information header"),
535 #ifdef DLT_ARCNET_LINUX
536 DLT_CHOICE(DLT_ARCNET_LINUX
, "Linux ARCNET"),
538 #ifdef DLT_LINUX_IRDA
539 DLT_CHOICE(DLT_LINUX_IRDA
, "Linux IrDA"),
541 #ifdef DLT_LINUX_LAPD
542 DLT_CHOICE(DLT_LINUX_LAPD
, "Linux vISDN LAPD"),
545 DLT_CHOICE(DLT_LANE8023
, "Linux 802.3 LANE"),
548 DLT_CHOICE(DLT_CIP
, "Linux Classical IP-over-ATM"),
551 DLT_CHOICE(DLT_HDLC
, "Cisco HDLC"),
554 DLT_CHOICE(DLT_PPI
, "Per-Packet Information"),
558 #endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION */
560 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
562 pcap_datalink_name_to_val(const char *name
)
568 if (p_pcap_datalink_name_to_val
!= NULL
)
569 return p_pcap_datalink_name_to_val(name
);
572 * We don't have it in WinPcap; do it ourselves.
574 for (i
= 0; dlt_choices
[i
].name
!= NULL
; i
++) {
575 if (g_ascii_strcasecmp(dlt_choices
[i
].name
+ sizeof("DLT_") - 1,
577 return dlt_choices
[i
].dlt
;
584 #ifdef HAVE_PCAP_LIST_DATALINKS
586 pcap_list_datalinks(pcap_t
*p
, int **ddlt
)
589 return p_pcap_list_datalinks(p
, ddlt
);
593 #ifdef HAVE_PCAP_FREE_DATALINKS
595 pcap_free_datalinks(int *ddlt
)
600 * If we don't have pcap_free_datalinks() in WinPcap,
601 * we don't free the memory - we can't use free(), as
602 * we might not have been built with the same version
603 * of the C runtime library as WinPcap was, and, if we're
604 * not, free() isn't guaranteed to work on something
605 * allocated by WinPcap.
607 if (p_pcap_free_datalinks
!= NULL
)
608 p_pcap_free_datalinks(ddlt
);
612 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
614 pcap_datalink_val_to_name(int dlt
)
620 if (p_pcap_datalink_val_to_name
!= NULL
)
621 return p_pcap_datalink_val_to_name(dlt
);
624 * We don't have it in WinPcap; do it ourselves.
626 for (i
= 0; dlt_choices
[i
].name
!= NULL
; i
++) {
627 if (dlt_choices
[i
].dlt
== dlt
)
628 return dlt_choices
[i
].name
+ sizeof("DLT_") - 1;
635 #ifdef HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION
637 pcap_datalink_val_to_description(int dlt
)
643 if (p_pcap_datalink_val_to_description
!= NULL
)
644 return p_pcap_datalink_val_to_description(dlt
);
647 * We don't have it in WinPcap; do it ourselves.
649 for (i
= 0; dlt_choices
[i
].name
!= NULL
; i
++) {
650 if (dlt_choices
[i
].dlt
== dlt
)
651 return (dlt_choices
[i
].description
);
658 #ifdef HAVE_PCAP_BREAKLOOP
659 void pcap_breakloop(pcap_t
*a
)
665 /* setbuff is win32 specific! */
666 int pcap_setbuff(pcap_t
*a
, int b
)
669 return p_pcap_setbuff(a
, b
);
672 /* pcap_next_ex is available since libpcap 0.8 / WinPcap 3.0! */
673 /* (if you get a declaration warning here, try to update to at least WinPcap 3.1b4 develpack) */
674 int pcap_next_ex (pcap_t
*a
, struct pcap_pkthdr
**b
, const u_char
**c
)
677 return p_pcap_next_ex(a
, b
, c
);
680 #ifdef HAVE_PCAP_REMOTE
682 get_remote_interface_list(const char *hostname
, const char *port
,
683 int auth_type
, const char *username
,
684 const char *passwd
, int *err
, char **err_str
)
686 struct pcap_rmtauth auth
;
687 char source
[PCAP_BUF_SIZE
];
688 char errbuf
[PCAP_ERRBUF_SIZE
];
691 if (pcap_createsrcstr(source
, PCAP_SRC_IFREMOTE
, hostname
, port
,
692 NULL
, errbuf
) == -1) {
693 *err
= CANT_GET_INTERFACE_LIST
;
695 *err_str
= cant_get_if_list_error_message(errbuf
);
699 auth
.type
= auth_type
;
700 auth
.username
= g_strdup(username
);
701 auth
.password
= g_strdup(passwd
);
703 result
= get_interface_list_findalldevs_ex(source
, &auth
, err
, err_str
);
704 g_free(auth
.username
);
705 g_free(auth
.password
);
712 * This will use "pcap_findalldevs()" if we have it, otherwise it'll
713 * fall back on "pcap_lookupdev()".
716 get_interface_list(int *err
, char **err_str
)
721 char ascii_name
[MAX_WIN_IF_NAME_LEN
+ 1];
722 char ascii_desc
[MAX_WIN_IF_NAME_LEN
+ 1];
724 char errbuf
[PCAP_ERRBUF_SIZE
];
728 * We don't have WinPcap, so we can't get a list of
731 *err
= DONT_HAVE_PCAP
;
732 *err_str
= cant_load_winpcap_err("you");
736 #ifdef HAVE_PCAP_FINDALLDEVS
737 if (p_pcap_findalldevs
!= NULL
)
738 return get_interface_list_findalldevs(err
, err_str
);
742 * In WinPcap, pcap_lookupdev is implemented by calling
743 * PacketGetAdapterNames. According to the documentation
746 * http://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
750 * On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence
751 * of bytes consisting of:
753 * a sequence of null-terminated ASCII strings (i.e., each
754 * one is terminated by a single 0 byte), giving the names
757 * an empty ASCII string (i.e., a single 0 byte);
759 * a sequence of null-terminated ASCII strings, giving the
760 * descriptions of the interfaces;
762 * an empty ASCII string.
764 * On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev
765 * returns a sequence of bytes consisting of:
767 * a sequence of null-terminated double-byte Unicode strings
768 * (i.e., each one consits of a sequence of double-byte
769 * characters, terminated by a double-byte 0), giving the
770 * names of the interfaces;
772 * an empty Unicode string (i.e., a double 0 byte);
774 * a sequence of null-terminated ASCII strings, giving the
775 * descriptions of the interfaces;
777 * an empty ASCII string.
779 * The Nth string in the first sequence is the name of the Nth
780 * adapter; the Nth string in the second sequence is the
781 * description of the Nth adapter.
784 names
= (wchar_t *)pcap_lookupdev(errbuf
);
793 * If names[0] is less than 256 it means the first
794 * byte is 0. This implies that we are using Unicode
797 while (*(names
+desc_pos
) || *(names
+desc_pos
-1))
799 desc_pos
++; /* Step over the extra '\0' */
800 desc
= (char*)(names
+ desc_pos
); /* cast *after* addition */
802 while (names
[i
] != 0) {
804 * Copy the Unicode description to an ASCII
809 if (j
< MAX_WIN_IF_NAME_LEN
)
810 ascii_desc
[j
++] = *desc
;
813 ascii_desc
[j
] = '\0';
817 * Copy the Unicode name to an ASCII string.
820 while (names
[i
] != 0) {
821 if (j
< MAX_WIN_IF_NAME_LEN
)
822 ascii_name
[j
++] = (char) names
[i
++];
824 ascii_name
[j
] = '\0';
826 il
= g_list_append(il
,
827 if_info_new(ascii_name
, ascii_desc
, FALSE
));
831 * Otherwise we are in Windows 95/98 and using ASCII
832 * (8-bit) characters.
834 win95names
=(char *)names
;
835 while (*(win95names
+desc_pos
) || *(win95names
+desc_pos
-1))
837 desc_pos
++; /* Step over the extra '\0' */
838 desc
= win95names
+ desc_pos
;
840 while (win95names
[i
] != '\0') {
842 * "&win95names[i]" points to the current
843 * interface name, and "desc" points to
844 * that interface's description.
846 il
= g_list_append(il
,
847 if_info_new(&win95names
[i
], desc
, FALSE
));
850 * Skip to the next description.
857 * Skip to the next name.
859 while (win95names
[i
] != 0)
868 * No interfaces found.
870 *err
= NO_INTERFACES_FOUND
;
879 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
880 * "get_interface_list()".
883 cant_get_if_list_error_message(const char *err_str
)
886 * If the error message includes "Not enough storage is available
887 * to process this command" or "The operation completed successfully",
888 * suggest that they install a WinPcap version later than 3.0.
890 if (strstr(err_str
, "Not enough storage is available to process this command") != NULL
||
891 strstr(err_str
, "The operation completed successfully") != NULL
) {
892 return g_strdup_printf("Can't get list of interfaces: %s\n"
893 "This might be a problem with WinPcap 3.0; you should try updating to\n"
894 "a later version of WinPcap - see the WinPcap site at www.winpcap.org",
897 return g_strdup_printf("Can't get list of interfaces: %s", err_str
);
901 * Append the version of WinPcap with which we were compiled to a GString.
904 get_compiled_pcap_version(GString
*str
)
906 g_string_append(str
, "with WinPcap (" G_STRINGIFY(PCAP_VERSION
) ")");
910 * Append the version of WinPcap with which we we're running to a GString.
913 get_runtime_pcap_version(GString
*str
)
916 * On Windows, we might have been compiled with WinPcap but
917 * might not have it loaded; indicate whether we have it or
918 * not and, if we have it and we have "pcap_lib_version()",
919 * what version we have.
921 GModule
*handle
; /* handle returned by ws_module_open */
922 static gchar
*packetVer
;
926 g_string_append_printf(str
, "with ");
927 if (p_pcap_lib_version
!= NULL
)
928 g_string_append_printf(str
, p_pcap_lib_version());
931 * An alternative method of obtaining the version
932 * number, by using the PacketLibraryVersion
933 * string from packet.dll.
935 * Unfortunately, in WinPcap 3.0, it returns
936 * "3.0 alpha3", even in the final version of
937 * WinPcap 3.0, so if there's a blank in the
938 * string, we strip it and everything after
939 * it from the string, so we don't misleadingly
940 * report that 3.0 alpha3 is being used when
941 * the final version is being used.
943 if (packetVer
== NULL
) {
944 packetVer
= "version unknown";
945 handle
= ws_module_open("packet.dll", 0);
946 if (handle
!= NULL
) {
947 if (g_module_symbol(handle
,
948 "PacketLibraryVersion",
949 (gpointer
*)&packetVer
)) {
950 packetVer
= g_strdup(packetVer
);
951 blankp
= strchr(packetVer
, ' ');
955 packetVer
= "version unknown";
957 g_module_close(handle
);
960 g_string_append_printf(str
, "WinPcap (%s)", packetVer
);
963 g_string_append(str
, "without WinPcap");
966 #else /* HAVE_LIBPCAP */
975 * Append an indication that we were not compiled with WinPcap
979 get_compiled_pcap_version(GString
*str
)
981 g_string_append(str
, "without WinPcap");
985 * Don't append anything, as we weren't even compiled to use WinPcap.
988 get_runtime_pcap_version(GString
*str _U_
)
992 #endif /* HAVE_LIBPCAP */