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