Update plugin to the current plugin design.
[obnox/wireshark/wip.git] / capture-wpcap.c
1 /* capture-wpcap.c
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.
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 2001 Gerald Combs
11  *
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.
16  *
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.
21  *
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_LIBPCAP
32 #include <pcap.h>
33 #endif
34
35 #include <glib.h>
36 #include <gmodule.h>
37
38 #include "capture-pcap-util.h"
39 #include "capture-pcap-util-int.h"
40
41 /* XXX - yes, I know, I should move cppmagic.h to a generic location. */
42 #include "tools/lemon/cppmagic.h"
43
44
45 #define MAX_WIN_IF_NAME_LEN 511
46
47
48 gboolean has_wpcap = FALSE;
49
50 #ifdef HAVE_LIBPCAP
51
52 /*
53  * XXX - should we require at least WinPcap 3.1 both for building an
54  * for using Wireshark?
55  */
56
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 *, char *, int,
66                         bpf_u_int32);
67 #ifdef WPCAP_CONSTIFIED
68 static int     (*p_pcap_lookupnet) (const char *, bpf_u_int32 *, bpf_u_int32 *,
69                         char *);
70 static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *);
71 #else
72 static int     (*p_pcap_lookupnet) (char *, bpf_u_int32 *, bpf_u_int32 *,
73                         char *);
74 static pcap_t* (*p_pcap_open_live) (char *, int, int, int, char *);
75 #endif
76 static int     (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
77 static void    (*p_pcap_freecode) (struct bpf_program *);
78 #ifdef HAVE_PCAP_FINDALLDEVS
79 static int     (*p_pcap_findalldevs) (pcap_if_t **, char *);
80 static void    (*p_pcap_freealldevs) (pcap_if_t *);
81 #endif
82 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
83 static int (*p_pcap_datalink_name_to_val) (const char *);
84 #endif
85 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
86 static const char *(*p_pcap_datalink_val_to_name) (int);
87 #endif
88 #ifdef HAVE_PCAP_BREAKLOOP
89 static void    (*p_pcap_breakloop) (pcap_t *);
90 #endif
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
95 typedef struct {
96         const char      *name;
97         gpointer        *ptr;
98         gboolean        optional;
99 } symbol_table_t;
100
101 #define SYM(x, y)       { STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
102
103 void
104 load_wpcap(void)
105 {
106
107         /* These are the symbols I need or want from Wpcap */
108         static const symbol_table_t     symbols[] = {
109                 SYM(pcap_lookupdev, FALSE),
110                 SYM(pcap_close, FALSE),
111                 SYM(pcap_stats, FALSE),
112                 SYM(pcap_dispatch, FALSE),
113                 SYM(pcap_snapshot, FALSE),
114                 SYM(pcap_datalink, FALSE),
115                 SYM(pcap_setfilter, FALSE),
116                 SYM(pcap_geterr, FALSE),
117                 SYM(pcap_compile, FALSE),
118                 SYM(pcap_lookupnet, FALSE),
119                 SYM(pcap_open_live, FALSE),
120                 SYM(pcap_loop, FALSE),
121                 SYM(pcap_freecode, TRUE),
122 #ifdef HAVE_PCAP_FINDALLDEVS
123                 SYM(pcap_findalldevs, TRUE),
124                 SYM(pcap_freealldevs, TRUE),
125 #endif
126 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
127                 SYM(pcap_datalink_name_to_val, TRUE),
128 #endif
129 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
130                 SYM(pcap_datalink_val_to_name, TRUE),
131 #endif
132 #ifdef HAVE_PCAP_BREAKLOOP
133                 /*
134                  * We don't try to work around the lack of this at
135                  * run time; it's present in WinPcap 3.1, which is
136                  * the version we build with and ship with.
137                  */
138                 SYM(pcap_breakloop, FALSE),
139 #endif
140                 SYM(pcap_lib_version, TRUE),
141                 SYM(pcap_setbuff, TRUE),
142                 SYM(pcap_next_ex, TRUE),
143                 { NULL, NULL, FALSE }
144         };
145
146         GModule         *wh; /* wpcap handle */
147         const symbol_table_t    *sym;
148
149         wh = g_module_open("wpcap", 0);
150
151         if (!wh) {
152                 return;
153         }
154
155         sym = symbols;
156         while (sym->name) {
157                 if (!g_module_symbol(wh, sym->name, sym->ptr)) {
158                         if (sym->optional) {
159                                 /*
160                                  * We don't care if it's missing; we just
161                                  * don't use it.
162                                  */
163                                 *sym->ptr = NULL;
164                         } else {
165                                 /*
166                                  * We require this symbol.
167                                  */
168                                 return;
169                         }
170                 }
171                 sym++;
172         }
173
174
175         has_wpcap = TRUE;
176 }
177
178 char*
179 pcap_lookupdev (char *a)
180 {
181         g_assert(has_wpcap);
182         return p_pcap_lookupdev(a);
183 }
184
185 void
186 pcap_close(pcap_t *a)
187 {
188         g_assert(has_wpcap);
189         p_pcap_close(a);
190 }
191
192 int
193 pcap_stats(pcap_t *a, struct pcap_stat *b)
194 {
195         g_assert(has_wpcap);
196         return p_pcap_stats(a, b);
197 }
198
199 int
200 pcap_dispatch(pcap_t *a, int b, pcap_handler c, guchar *d)
201 {
202         g_assert(has_wpcap);
203         return p_pcap_dispatch(a, b, c, d);
204 }
205
206 int
207 pcap_snapshot(pcap_t *a)
208 {
209         g_assert(has_wpcap);
210         return p_pcap_snapshot(a);
211 }
212
213 int
214 pcap_datalink(pcap_t *a)
215 {
216         g_assert(has_wpcap);
217         return p_pcap_datalink(a);
218 }
219
220 int
221 pcap_setfilter(pcap_t *a, struct bpf_program *b)
222 {
223         g_assert(has_wpcap);
224         return p_pcap_setfilter(a, b);
225 }
226
227 char*
228 pcap_geterr(pcap_t *a)
229 {
230         g_assert(has_wpcap);
231         return p_pcap_geterr(a);
232 }
233
234 int
235 pcap_compile(pcap_t *a, struct bpf_program *b, char *c, int d,
236             bpf_u_int32 e)
237 {
238         g_assert(has_wpcap);
239         return p_pcap_compile(a, b, c, d, e);
240 }
241
242 int
243 #ifdef WPCAP_CONSTIFIED
244 pcap_lookupnet(const char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
245 #else
246 pcap_lookupnet(char *a, bpf_u_int32 *b, bpf_u_int32 *c, char *d)
247 #endif
248 {
249         g_assert(has_wpcap);
250         return p_pcap_lookupnet(a, b, c, d);
251 }
252
253 pcap_t*
254 #ifdef WPCAP_CONSTIFIED
255 pcap_open_live(const char *a, int b, int c, int d, char *e)
256 #else
257 pcap_open_live(char *a, int b, int c, int d, char *e)
258 #endif
259 {
260         g_assert(has_wpcap);
261         return p_pcap_open_live(a, b, c, d, e);
262 }
263
264 int
265 pcap_loop(pcap_t *a, int b, pcap_handler c, guchar *d)
266 {
267         g_assert(has_wpcap);
268         return p_pcap_loop(a, b, c, d);
269 }
270
271 void
272 pcap_freecode(struct bpf_program *a)
273 {
274         g_assert(has_wpcap);
275     if(p_pcap_freecode) {
276             p_pcap_freecode(a);
277     }
278 }
279
280 #ifdef HAVE_PCAP_FINDALLDEVS
281 int
282 pcap_findalldevs(pcap_if_t **a, char *b)
283 {
284         g_assert(has_wpcap && p_pcap_findalldevs != NULL);
285         return p_pcap_findalldevs(a, b);
286 }
287
288 void
289 pcap_freealldevs(pcap_if_t *a)
290 {
291         g_assert(has_wpcap && p_pcap_freealldevs != NULL);
292         p_pcap_freealldevs(a);
293 }
294 #endif
295
296 #if defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME)
297 /*
298  * Table of DLT_ types, names, and descriptions, for use if the version
299  * of WinPcap we have installed lacks "pcap_datalink_name_to_val()"
300  * or "pcap_datalink_val_to_name()".
301  */
302 struct dlt_choice {
303         const char *name;
304         const char *description;
305         int     dlt;
306 };
307
308 #define DLT_CHOICE(code, description) { #code, description, code }
309 #define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
310
311 static struct dlt_choice dlt_choices[] = {
312         DLT_CHOICE(DLT_NULL, "BSD loopback"),
313         DLT_CHOICE(DLT_EN10MB, "Ethernet"),
314         DLT_CHOICE(DLT_IEEE802, "Token ring"),
315         DLT_CHOICE(DLT_ARCNET, "ARCNET"),
316         DLT_CHOICE(DLT_SLIP, "SLIP"),
317         DLT_CHOICE(DLT_PPP, "PPP"),
318         DLT_CHOICE(DLT_FDDI, "FDDI"),
319         DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"),
320         DLT_CHOICE(DLT_RAW, "Raw IP"),
321 #ifdef DLT_SLIP_BSDOS
322         DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"),
323 #endif
324 #ifdef DLT_PPP_BSDOS
325         DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
326 #endif
327 #ifdef DLT_ATM_CLIP
328         DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
329 #endif
330 #ifdef DLT_PPP_SERIAL
331         DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
332 #endif
333 #ifdef DLT_PPP_ETHER
334         DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
335 #endif
336 #ifdef DLT_C_HDLC
337         DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
338 #endif
339 #ifdef DLT_IEEE802_11
340         DLT_CHOICE(DLT_IEEE802_11, "802.11"),
341 #endif
342 #ifdef DLT_FRELAY
343         DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
344 #endif
345 #ifdef DLT_LOOP
346         DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
347 #endif
348 #ifdef DLT_ENC
349         DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
350 #endif
351 #ifdef DLT_LINUX_SLL
352         DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
353 #endif
354 #ifdef DLT_LTALK
355         DLT_CHOICE(DLT_LTALK, "Localtalk"),
356 #endif
357 #ifdef DLT_PFLOG
358         DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"),
359 #endif
360 #ifdef DLT_PRISM_HEADER
361         DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"),
362 #endif
363 #ifdef DLT_IP_OVER_FC
364         DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"),
365 #endif
366 #ifdef DLT_SUNATM
367         DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"),
368 #endif
369 #ifdef DLT_IEEE802_11_RADIO
370         DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus radio information header"),
371 #endif
372 #ifdef DLT_ARCNET_LINUX
373         DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"),
374 #endif
375 #ifdef DLT_LINUX_IRDA
376         DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
377 #endif
378 #ifdef DLT_LINUX_LAPD
379         DLT_CHOICE(DLT_LINUX_LAPD, "Linux vISDN LAPD"),
380 #endif
381 #ifdef DLT_LANE8023
382         DLT_CHOICE(DLT_LANE8023, "Linux 802.3 LANE"),
383 #endif
384 #ifdef DLT_CIP
385         DLT_CHOICE(DLT_CIP, "Linux Classical IP-over-ATM"),
386 #endif
387 #ifdef DLT_HDLC
388         DLT_CHOICE(DLT_HDLC, "Cisco HDLC"),
389 #endif
390         DLT_CHOICE_SENTINEL
391 };
392 #endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) */
393
394 #ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
395 int
396 pcap_datalink_name_to_val(const char *name)
397 {
398         int i;
399
400         g_assert(has_wpcap);
401
402         if (p_pcap_datalink_name_to_val != NULL)
403                 return p_pcap_datalink_name_to_val(name);
404         else {
405                 /*
406                  * We don't have it in WinPcap; do it ourselves.
407                  */
408                 for (i = 0; dlt_choices[i].name != NULL; i++) {
409                         if (strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
410                             name) == 0)
411                                 return dlt_choices[i].dlt;
412                 }
413                 return -1;
414         }
415 }
416 #endif
417
418 #ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
419 const char *
420 pcap_datalink_val_to_name(int dlt)
421 {
422         int i;
423
424         g_assert(has_wpcap);
425
426         if (p_pcap_datalink_val_to_name != NULL)
427                 return p_pcap_datalink_val_to_name(dlt);
428         else {
429                 /*
430                  * We don't have it in WinPcap; do it ourselves.
431                  */
432                 for (i = 0; dlt_choices[i].name != NULL; i++) {
433                         if (dlt_choices[i].dlt == dlt)
434                                 return dlt_choices[i].name + sizeof("DLT_") - 1;
435                 }
436                 return NULL;
437         }
438 }
439 #endif
440
441 #ifdef HAVE_PCAP_BREAKLOOP
442 void pcap_breakloop(pcap_t *a)
443 {
444         p_pcap_breakloop(a);
445 }
446 #endif
447
448 /* setbuff is win32 specific! */
449 int pcap_setbuff(pcap_t *a, int b)
450 {
451         g_assert(has_wpcap);
452         return p_pcap_setbuff(a, b);
453 }
454
455 /* pcap_next_ex is available since libpcap 0.8 / WinPcap 3.0! */
456 /* (if you get a declaration warning here, try to update to at least WinPcap 3.1b4 develpack) */
457 int pcap_next_ex (pcap_t *a, struct pcap_pkthdr **b, const u_char **c)
458 {
459         g_assert(has_wpcap);
460         return p_pcap_next_ex(a, b, c);
461 }
462
463 /*
464  * This will use "pcap_findalldevs()" if we have it, otherwise it'll
465  * fall back on "pcap_lookupdev()".
466  */
467 GList *
468 get_interface_list(int *err, char *err_str)
469 {
470         GList  *il = NULL;
471         wchar_t *names;
472         char *win95names;
473         char ascii_name[MAX_WIN_IF_NAME_LEN + 1];
474         char ascii_desc[MAX_WIN_IF_NAME_LEN + 1];
475         int i, j;
476
477 #ifdef HAVE_PCAP_FINDALLDEVS
478         if (p_pcap_findalldevs != NULL)
479                 return get_interface_list_findalldevs(err, err_str);
480 #endif
481
482         /*
483          * In WinPcap, pcap_lookupdev is implemented by calling
484          * PacketGetAdapterNames.  According to the documentation
485          * I could find:
486          *
487          *      http://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
488          *
489          * this means that:
490          *
491          * On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence
492          * of bytes consisting of:
493          *
494          *      a sequence of null-terminated ASCII strings (i.e., each
495          *      one is terminated by a single 0 byte), giving the names
496          *      of the interfaces;
497          *
498          *      an empty ASCII string (i.e., a single 0 byte);
499          *
500          *      a sequence of null-terminated ASCII strings, giving the
501          *      descriptions of the interfaces;
502          *
503          *      an empty ASCII string.
504          *
505          * On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev
506          * returns a sequence of bytes consisting of:
507          *
508          *      a sequence of null-terminated double-byte Unicode strings
509          *      (i.e., each one consits of a sequence of double-byte
510          *      characters, terminated by a double-byte 0), giving the
511          *      names of the interfaces;
512          *
513          *      an empty Unicode string (i.e., a double 0 byte);
514          *
515          *      a sequence of null-terminated ASCII strings, giving the
516          *      descriptions of the interfaces;
517          *
518          *      an empty ASCII string.
519          *
520          * The Nth string in the first sequence is the name of the Nth
521          * adapter; the Nth string in the second sequence is the
522          * description of the Nth adapter.
523          */
524
525         names = (wchar_t *)pcap_lookupdev(err_str);
526         i = 0;
527
528         if (names) {
529                 char* desc = 0;
530                 int desc_pos = 0;
531
532                 if (names[0]<256) {
533                         /*
534                          * If names[0] is less than 256 it means the first
535                          * byte is 0.  This implies that we are using Unicode
536                          * characters.
537                          */
538                         while (*(names+desc_pos) || *(names+desc_pos-1))
539                                 desc_pos++;
540                         desc_pos++;     /* Step over the extra '\0' */
541                         desc = (char*)(names + desc_pos); /* cast *after* addition */
542
543                         while (names[i] != 0) {
544                                 /*
545                                  * Copy the Unicode description to an ASCII
546                                  * string.
547                                  */
548                                 j = 0;
549                                 while (*desc != 0) {
550                                         if (j < MAX_WIN_IF_NAME_LEN)
551                                                 ascii_desc[j++] = *desc;
552                                         desc++;
553                                 }
554                                 ascii_desc[j] = '\0';
555                                 desc++;
556
557                                 /*
558                                  * Copy the Unicode name to an ASCII string.
559                                  */
560                                 j = 0;
561                                 while (names[i] != 0) {
562                                         if (j < MAX_WIN_IF_NAME_LEN)
563                                         ascii_name[j++] = (char) names[i++];
564                                 }
565                                 ascii_name[j] = '\0';
566                                 i++;
567                                 il = g_list_append(il,
568                                     if_info_new(ascii_name, ascii_desc));
569                         }
570                 } else {
571                         /*
572                          * Otherwise we are in Windows 95/98 and using ASCII
573                          * (8-bit) characters.
574                          */
575                         win95names=(char *)names;
576                         while (*(win95names+desc_pos) || *(win95names+desc_pos-1))
577                                 desc_pos++;
578                         desc_pos++;     /* Step over the extra '\0' */
579                         desc = win95names + desc_pos;
580
581                         while (win95names[i] != '\0') {
582                                 /*
583                                  * "&win95names[i]" points to the current
584                                  * interface name, and "desc" points to
585                                  * that interface's description.
586                                  */
587                                 il = g_list_append(il,
588                                     if_info_new(&win95names[i], desc));
589
590                                 /*
591                                  * Skip to the next description.
592                                  */
593                                 while (*desc != 0)
594                                         desc++;
595                                 desc++;
596
597                                 /*
598                                  * Skip to the next name.
599                                  */
600                                 while (win95names[i] != 0)
601                                         i++;
602                                 i++;
603                         }
604                 }
605         }
606
607         if (il == NULL) {
608                 /*
609                  * No interfaces found.
610                  */
611                 *err = NO_INTERFACES_FOUND;
612         }
613
614         return il;
615 }
616
617 /*
618  * Get an error message string for a CANT_GET_INTERFACE_LIST error from
619  * "get_interface_list()".
620  */
621 gchar *
622 cant_get_if_list_error_message(const char *err_str)
623 {
624         /*
625          * If the error message includes "Not enough storage is available
626          * to process this command" or "The operation completed successfully",
627          * suggest that they install a WinPcap version later than 3.0.
628          */
629         if (strstr(err_str, "Not enough storage is available to process this command") != NULL ||
630             strstr(err_str, "The operation completed successfully") != NULL) {
631                 return g_strdup_printf("Can't get list of interfaces: %s\n"
632 "This might be a problem with WinPcap 3.0; you should try updating to\n"
633 "a later version of WinPcap - see the WinPcap site at www.winpcap.org",
634                     err_str);
635         }
636         return g_strdup_printf("Can't get list of interfaces: %s", err_str);
637 }
638
639 /*
640  * Append the version of WinPcap with which we were compiled to a GString.
641  */
642 void
643 get_compiled_pcap_version(GString *str)
644 {
645         g_string_append(str, "with WinPcap (version unknown)");
646 }
647
648 /*
649  * Append the version of WinPcap with which we we're running to a GString.
650  */
651 void
652 get_runtime_pcap_version(GString *str)
653 {
654         /*
655          * On Windows, we might have been compiled with WinPcap but
656          * might not have it loaded; indicate whether we have it or
657          * not and, if we have it and we have "pcap_lib_version()",
658          * what version we have.
659          */
660         GModule *handle;                /* handle returned by dlopen */
661         static gchar *packetVer;
662         gchar *blankp;
663
664         if (has_wpcap) {
665                 g_string_sprintfa(str, "with ");
666                 if (p_pcap_lib_version != NULL)
667                         g_string_sprintfa(str, p_pcap_lib_version());
668                 else {
669                         /*
670                          * An alternative method of obtaining the version
671                          * number, by using the PacketLibraryVersion
672                          * string from packet.dll.
673                          *
674                          * Unfortunately, in WinPcap 3.0, it returns
675                          * "3.0 alpha3", even in the final version of
676                          * WinPcap 3.0, so if there's a blank in the
677                          * string, we strip it and everything after
678                          * it from the string, so we don't misleadingly
679                          * report that 3.0 alpha3 is being used when
680                          * the final version is being used.
681                          */
682                         if (packetVer == NULL) {
683                                 packetVer = "version unknown";
684                                 handle = g_module_open("Packet.dll", 0);
685                                 if (handle != NULL) {
686                                         if (g_module_symbol(handle,
687                                             "PacketLibraryVersion",
688                                             (gpointer*)&packetVer)) {
689                                                 packetVer = g_strdup(packetVer);
690                                                 blankp = strchr(packetVer, ' ');
691                                                 if (blankp != NULL)
692                                                         *blankp = '\0';
693                                         } else {
694                                                 packetVer = "version unknown";
695                                         }
696                                         g_module_close(handle);
697                                 }
698                         }
699                         g_string_sprintfa(str, "WinPcap (%s)", packetVer);
700                 }
701         } else
702                 g_string_append(str, "without WinPcap");
703 }
704
705 #else /* HAVE_LIBPCAP */
706
707 void
708 load_wpcap(void)
709 {
710         return;
711 }
712
713 /*
714  * Append an indication that we were not compiled with WinPcap
715  * to a GString.
716  */
717 void
718 get_compiled_pcap_version(GString *str)
719 {
720         g_string_append(str, "without WinPcap");
721 }
722
723 /*
724  * Don't append anything, as we weren't even compiled to use WinPcap.
725  */
726 void
727 get_runtime_pcap_version(GString *str _U_)
728 {
729 }
730
731 #endif /* HAVE_LIBPCAP */