Have the routines to get interface lists take a pointer to a "gchar *"
[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         char errbuf[PCAP_ERRBUF_SIZE];
477
478 #ifdef HAVE_PCAP_FINDALLDEVS
479         if (p_pcap_findalldevs != NULL)
480                 return get_interface_list_findalldevs(err, err_str);
481 #endif
482
483         /*
484          * In WinPcap, pcap_lookupdev is implemented by calling
485          * PacketGetAdapterNames.  According to the documentation
486          * I could find:
487          *
488          *      http://www.winpcap.org/docs/man/html/Packet32_8c.html#a43
489          *
490          * this means that:
491          *
492          * On Windows OT (95, 98, Me), pcap_lookupdev returns a sequence
493          * of bytes consisting of:
494          *
495          *      a sequence of null-terminated ASCII strings (i.e., each
496          *      one is terminated by a single 0 byte), giving the names
497          *      of the interfaces;
498          *
499          *      an empty ASCII string (i.e., a single 0 byte);
500          *
501          *      a sequence of null-terminated ASCII strings, giving the
502          *      descriptions of the interfaces;
503          *
504          *      an empty ASCII string.
505          *
506          * On Windows NT (NT 4.0, W2K, WXP, W2K3, etc.), pcap_lookupdev
507          * returns a sequence of bytes consisting of:
508          *
509          *      a sequence of null-terminated double-byte Unicode strings
510          *      (i.e., each one consits of a sequence of double-byte
511          *      characters, terminated by a double-byte 0), giving the
512          *      names of the interfaces;
513          *
514          *      an empty Unicode string (i.e., a double 0 byte);
515          *
516          *      a sequence of null-terminated ASCII strings, giving the
517          *      descriptions of the interfaces;
518          *
519          *      an empty ASCII string.
520          *
521          * The Nth string in the first sequence is the name of the Nth
522          * adapter; the Nth string in the second sequence is the
523          * description of the Nth adapter.
524          */
525
526         names = (wchar_t *)pcap_lookupdev(errbuf);
527         i = 0;
528
529         if (names) {
530                 char* desc = 0;
531                 int desc_pos = 0;
532
533                 if (names[0]<256) {
534                         /*
535                          * If names[0] is less than 256 it means the first
536                          * byte is 0.  This implies that we are using Unicode
537                          * characters.
538                          */
539                         while (*(names+desc_pos) || *(names+desc_pos-1))
540                                 desc_pos++;
541                         desc_pos++;     /* Step over the extra '\0' */
542                         desc = (char*)(names + desc_pos); /* cast *after* addition */
543
544                         while (names[i] != 0) {
545                                 /*
546                                  * Copy the Unicode description to an ASCII
547                                  * string.
548                                  */
549                                 j = 0;
550                                 while (*desc != 0) {
551                                         if (j < MAX_WIN_IF_NAME_LEN)
552                                                 ascii_desc[j++] = *desc;
553                                         desc++;
554                                 }
555                                 ascii_desc[j] = '\0';
556                                 desc++;
557
558                                 /*
559                                  * Copy the Unicode name to an ASCII string.
560                                  */
561                                 j = 0;
562                                 while (names[i] != 0) {
563                                         if (j < MAX_WIN_IF_NAME_LEN)
564                                         ascii_name[j++] = (char) names[i++];
565                                 }
566                                 ascii_name[j] = '\0';
567                                 i++;
568                                 il = g_list_append(il,
569                                     if_info_new(ascii_name, ascii_desc));
570                         }
571                 } else {
572                         /*
573                          * Otherwise we are in Windows 95/98 and using ASCII
574                          * (8-bit) characters.
575                          */
576                         win95names=(char *)names;
577                         while (*(win95names+desc_pos) || *(win95names+desc_pos-1))
578                                 desc_pos++;
579                         desc_pos++;     /* Step over the extra '\0' */
580                         desc = win95names + desc_pos;
581
582                         while (win95names[i] != '\0') {
583                                 /*
584                                  * "&win95names[i]" points to the current
585                                  * interface name, and "desc" points to
586                                  * that interface's description.
587                                  */
588                                 il = g_list_append(il,
589                                     if_info_new(&win95names[i], desc));
590
591                                 /*
592                                  * Skip to the next description.
593                                  */
594                                 while (*desc != 0)
595                                         desc++;
596                                 desc++;
597
598                                 /*
599                                  * Skip to the next name.
600                                  */
601                                 while (win95names[i] != 0)
602                                         i++;
603                                 i++;
604                         }
605                 }
606         }
607
608         if (il == NULL) {
609                 /*
610                  * No interfaces found.
611                  */
612                 *err = NO_INTERFACES_FOUND;
613                 if (err_str != NULL)
614                         *err_str = NULL;
615         }
616
617         return il;
618 }
619
620 /*
621  * Get an error message string for a CANT_GET_INTERFACE_LIST error from
622  * "get_interface_list()".
623  */
624 gchar *
625 cant_get_if_list_error_message(const char *err_str)
626 {
627         /*
628          * If the error message includes "Not enough storage is available
629          * to process this command" or "The operation completed successfully",
630          * suggest that they install a WinPcap version later than 3.0.
631          */
632         if (strstr(err_str, "Not enough storage is available to process this command") != NULL ||
633             strstr(err_str, "The operation completed successfully") != NULL) {
634                 return g_strdup_printf("Can't get list of interfaces: %s\n"
635 "This might be a problem with WinPcap 3.0; you should try updating to\n"
636 "a later version of WinPcap - see the WinPcap site at www.winpcap.org",
637                     err_str);
638         }
639         return g_strdup_printf("Can't get list of interfaces: %s", err_str);
640 }
641
642 /*
643  * Append the version of WinPcap with which we were compiled to a GString.
644  */
645 void
646 get_compiled_pcap_version(GString *str)
647 {
648         g_string_append(str, "with WinPcap (version unknown)");
649 }
650
651 /*
652  * Append the version of WinPcap with which we we're running to a GString.
653  */
654 void
655 get_runtime_pcap_version(GString *str)
656 {
657         /*
658          * On Windows, we might have been compiled with WinPcap but
659          * might not have it loaded; indicate whether we have it or
660          * not and, if we have it and we have "pcap_lib_version()",
661          * what version we have.
662          */
663         GModule *handle;                /* handle returned by dlopen */
664         static gchar *packetVer;
665         gchar *blankp;
666
667         if (has_wpcap) {
668                 g_string_sprintfa(str, "with ");
669                 if (p_pcap_lib_version != NULL)
670                         g_string_sprintfa(str, p_pcap_lib_version());
671                 else {
672                         /*
673                          * An alternative method of obtaining the version
674                          * number, by using the PacketLibraryVersion
675                          * string from packet.dll.
676                          *
677                          * Unfortunately, in WinPcap 3.0, it returns
678                          * "3.0 alpha3", even in the final version of
679                          * WinPcap 3.0, so if there's a blank in the
680                          * string, we strip it and everything after
681                          * it from the string, so we don't misleadingly
682                          * report that 3.0 alpha3 is being used when
683                          * the final version is being used.
684                          */
685                         if (packetVer == NULL) {
686                                 packetVer = "version unknown";
687                                 handle = g_module_open("Packet.dll", 0);
688                                 if (handle != NULL) {
689                                         if (g_module_symbol(handle,
690                                             "PacketLibraryVersion",
691                                             (gpointer*)&packetVer)) {
692                                                 packetVer = g_strdup(packetVer);
693                                                 blankp = strchr(packetVer, ' ');
694                                                 if (blankp != NULL)
695                                                         *blankp = '\0';
696                                         } else {
697                                                 packetVer = "version unknown";
698                                         }
699                                         g_module_close(handle);
700                                 }
701                         }
702                         g_string_sprintfa(str, "WinPcap (%s)", packetVer);
703                 }
704         } else
705                 g_string_append(str, "without WinPcap");
706 }
707
708 #else /* HAVE_LIBPCAP */
709
710 void
711 load_wpcap(void)
712 {
713         return;
714 }
715
716 /*
717  * Append an indication that we were not compiled with WinPcap
718  * to a GString.
719  */
720 void
721 get_compiled_pcap_version(GString *str)
722 {
723         g_string_append(str, "without WinPcap");
724 }
725
726 /*
727  * Don't append anything, as we weren't even compiled to use WinPcap.
728  */
729 void
730 get_runtime_pcap_version(GString *str _U_)
731 {
732 }
733
734 #endif /* HAVE_LIBPCAP */