Fix WEP key bug in the AirPcap code that could cause a crash. Enable
[obnox/wireshark/wip.git] / airpcap_loader.c
1 /* airpcap_loader.c
2  *
3  * $Id$
4  *
5  * Giorgio Tino <giorgio.tino@cacetech.com>
6  * Copyright (c) CACE Technologies, LLC 2006
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 2000 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 _WIN32
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #ifdef HAVE_LIBPCAP
34 #include <glib.h>
35 #include <gmodule.h>
36
37
38 #include <wtap.h>
39 #include <pcap.h>
40 #endif
41
42 #include "capture_ui_utils.h"
43 #include <epan/prefs.h>
44
45 #include "simple_dialog.h"
46
47 #include <airpcap.h>
48 #include "airpcap_loader.h"
49
50 /*
51  * We load dinamically the dag library in order link it only when
52  * it's present on the system
53  */
54 static HMODULE AirpcapLib;
55
56 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
57 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
58 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
59 static AirpcapOpenHandler g_PAirpcapOpen;
60 static AirpcapCloseHandler g_PAirpcapClose;
61 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
62 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
63 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
64 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
65 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
66 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
67 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
68 static AirpcapReadHandler g_PAirpcapRead;
69 static AirpcapGetStatsHandler g_PAirpcapGetStats;
70 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
71 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
72 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
73 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
74 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
75 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
76 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
77 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
78 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
79 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
80 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
81 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
82 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
83
84 /* Airpcap interface list */
85 GList *airpcap_if_list = NULL;
86
87 /* Airpcap current selected interface */
88 airpcap_if_info_t *airpcap_if_selected = NULL;
89
90 /* Airpcap current active interface */
91 airpcap_if_info_t *airpcap_if_active = NULL;
92
93 /*
94  * Get an error message string for a CANT_GET_INTERFACE_LIST error from
95  * "get_airpcap_interface_list()".
96  */
97 gchar *
98 cant_get_airpcap_if_list_error_message(const char *err_str)
99 {
100         return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
101 }
102
103 /*
104  * Airpcap wrapper, used to store the current settings for the selected adapter
105  */
106 BOOL
107 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
108 {
109         return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
110 }
111
112 /*
113  * Airpcap wrapper, used to open an airpcap adapter
114  */
115 PAirpcapHandle
116 airpcap_if_open(PCHAR name, PCHAR err)
117 {
118         return g_PAirpcapOpen(name,err);
119 }
120
121 /*
122  * Airpcap wrapper, used to close an airpcap adapter
123  */
124 VOID
125 airpcap_if_close(PAirpcapHandle handle)
126 {
127 g_PAirpcapClose(handle);
128
129 }
130
131 /*
132  * Airpcap wrapper, used to turn on the led of an airpcap adapter
133  */
134 BOOL
135 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber)
136 {
137         return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
138 }
139
140 /*
141  * Airpcap wrapper, used to turn off the led of an airpcap adapter
142  */
143 BOOL
144 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber)
145 {
146         return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
147 }
148
149 /*
150  * Airpcap wrapper, used to get the channel of an airpcap adapter
151  */
152 BOOL
153 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch)
154 {
155         return g_PAirpcapGetDeviceChannel(ah,ch);
156 }
157
158 /*
159  * Airpcap wrapper, used to set the channel of an airpcap adapter
160  */
161 BOOL
162 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch)
163 {
164         return g_PAirpcapSetDeviceChannel(ah,ch);
165 }
166
167 /*
168  * Airpcap wrapper, used to get the link type of an airpcap adapter
169  */
170 BOOL
171 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
172 {
173         return g_PAirpcapGetLinkType(ah,lt);
174 }
175
176 /*
177  * Airpcap wrapper, used to set the link type of an airpcap adapter
178  */
179 BOOL
180 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
181 {
182         return g_PAirpcapSetLinkType(ah,lt);
183 }
184
185 /*
186  * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
187  */
188 BOOL
189 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL fcs)
190 {
191         return g_PAirpcapGetFcsPresence(ah,fcs);
192 }
193
194 /*
195  * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
196  */
197 BOOL
198 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL fcs)
199 {
200         return g_PAirpcapSetFcsPresence(ah,fcs);
201 }
202
203 /*
204  * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
205  */
206 BOOL
207 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
208 {
209         return g_PAirpcapGetDecryptionState(ah,PEnable);
210 }
211
212 /*
213  * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
214  */
215 BOOL
216 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
217 {
218         return g_PAirpcapSetDecryptionState(ah,Enable);
219 }
220
221 /*
222  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
223  */
224 BOOL
225 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
226 {
227         return g_PAirpcapGetFcsValidation(ah,val);
228 }
229
230 /*
231  * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
232  */
233 BOOL
234 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
235 {
236         return g_PAirpcapSetFcsValidation(ah,val);
237 }
238
239 /*
240  * Airpcap wrapper, used to save the settings for the selected_if
241  */
242 BOOL
243 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
244 {
245         return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
246 }
247
248 /*
249  * Airpcap wrapper, used to save the settings for the selected_if
250  */
251 BOOL
252 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize)
253 {
254         return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
255 }
256
257 /*
258  * This function will create a new airpcap_if_info_t using a name and a description
259  */
260 airpcap_if_info_t *
261 airpcap_if_info_new(char *name, char *description)
262 {
263 PAirpcapHandle ad;
264 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
265
266         airpcap_if_info_t *if_info;
267
268         if_info = g_malloc(sizeof (airpcap_if_info_t));
269         if_info->name = g_strdup(name);
270         if (description == NULL)
271                 if_info->description = NULL;
272         else
273                 if_info->description = g_strdup(description);
274         if_info->ip_addr = NULL;
275         if_info->loopback = FALSE;
276
277         /* Probably I have to switch on the leds!!! */
278         ad = airpcap_if_open(if_info->name, ebuf);
279         if(ad)
280                 {
281                 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
282                 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
283                 airpcap_if_get_link_type(ad,&(if_info->linkType));
284                 airpcap_if_get_device_channel(ad,&(if_info->channel));
285                 airpcap_if_turn_led_on(ad, 0);
286                 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
287                 if_info->led = TRUE;
288                 if_info->blinking = FALSE;
289                 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
290
291                 /* get the keys, if everything is ok, close the adapter */
292                 if(airpcap_if_load_keys(ad,if_info))
293                         airpcap_if_close(ad);
294                 }
295         return if_info;
296 }
297
298 /*
299  * Function used to load the WEP keys for a selected interface
300  */
301 BOOL
302 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
303 {
304 if_info->keysCollectionSize = 0;
305 if_info->keysCollection = NULL;
306
307 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
308         {
309         if(if_info->keysCollectionSize == 0)
310                 {
311                 if_info->keysCollection = NULL;
312                 airpcap_if_close(ad);
313                 return FALSE;
314                 }
315
316         if_info->keysCollection = (PAirpcapKeysCollection)malloc(if_info->keysCollectionSize);
317         if(!if_info->keysCollection)
318                 {
319                 if_info->keysCollectionSize = 0;
320                 if_info->keysCollection = NULL;
321                 airpcap_if_close(ad);
322                 return FALSE;
323                 }
324
325         airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
326         return TRUE;
327         }
328 airpcap_if_close(ad);
329 return FALSE;
330 }
331
332 /*
333  * Function used to save the WEP keys for a selected interface
334  */
335 void
336 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
337 {
338         if(if_info->keysCollection != NULL)
339                 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
340 }
341
342 /*
343  * Callback used to free an instance of airpcap_if_info_t
344  */
345 static void
346 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
347 {
348         airpcap_if_info_t *if_info = data;
349
350         if (if_info->name != NULL)
351                 g_free(if_info->name);
352
353         if (if_info->description != NULL)
354                 g_free(if_info->description);
355
356         /* XXX - FREE THE WEP KEY LIST HERE!!!*/
357         if(if_info->keysCollection != NULL)
358                 g_free(if_info->keysCollection);
359
360         if(if_info->ip_addr != NULL)
361                 g_slist_free(if_info->ip_addr);
362
363         if(if_info != NULL)
364                 g_free(if_info);
365 }
366
367 /*
368  * Function used to free the airpcap interface list
369  */
370 void
371 free_airpcap_interface_list(GList *if_list)
372 {
373         g_list_foreach(if_list, free_airpcap_if_cb, NULL);
374         g_list_free(if_list);
375         if_list = NULL;
376 }
377
378 /*
379  * This function will use the airpcap.dll to find all the airpcap devices.
380  * Will return null if no device is found.
381  */
382 GList*
383 get_airpcap_interface_list(int *err, char *err_str)
384 {
385         GList  *il = NULL;
386         airpcap_if_info_t *if_info;
387         int i, n_adapts;
388     AirpcapDeviceDescription *devsList, *adListEntry;
389
390         if(!g_PAirpcapGetDeviceList(&devsList, err_str))
391         {
392                 /* No interfaces, return il = NULL; */
393                 *err = NO_AIRPCAP_INTERFACES_FOUND;
394                 return il;
395         }
396
397         /*
398          * Count the adapters
399          */
400         adListEntry = devsList;
401         n_adapts = 0;
402         while(adListEntry)
403         {
404                 n_adapts++;
405                 adListEntry = adListEntry->next;
406         }
407
408         if(n_adapts == 0)
409         {
410                 /* No interfaces, return il= NULL */
411                 g_PAirpcapFreeDeviceList(devsList);
412                 *err = NO_AIRPCAP_INTERFACES_FOUND;
413                 return il;
414         }
415
416         /*
417          * Insert the adapters in our list
418          */
419         adListEntry = devsList;
420         for(i = 0; i < n_adapts; i++)
421         {
422                 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
423         il = g_list_append(il, if_info);
424
425                 adListEntry = adListEntry->next;
426         }
427
428         g_PAirpcapFreeDeviceList(devsList);
429
430         return il;
431 }
432
433 /*
434  * Used to retrieve the name of the interface given the description
435  * (the name is used in AirpcapOpen, the description is put in the combo box)
436  */
437 gchar* get_airpcap_name_from_description(GList* if_list, gchar* description)
438 {
439 unsigned int ifn;
440 GList* curr;
441 airpcap_if_info_t* if_info;
442
443 ifn = 0;
444 if(if_list != NULL)
445         {
446         while( ifn < g_list_length(if_list) )
447                 {
448                 curr = g_list_nth(if_list, ifn);
449
450                 if_info = NULL;
451                 if(curr != NULL)
452                         if_info = curr->data;
453                 if(if_info != NULL)
454                         if ( g_ascii_strcasecmp(if_info->description,description) == 0)
455                                 {
456                                 return if_info->name;
457                                 }
458                 ifn++;
459                 }
460         }
461 return NULL;
462 }
463
464 /*
465  * Used to retrieve the interface given the name
466  * (the name is used in AirpcapOpen)
467  */
468 airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name)
469 {
470 unsigned int ifn;
471 GList* curr;
472 airpcap_if_info_t* if_info;
473
474 ifn = 0;
475 if(if_list != NULL)
476         {
477         while( ifn < g_list_length(if_list) )
478                 {
479                 curr = g_list_nth(if_list, ifn);
480
481                 if_info = NULL;
482                 if(curr != NULL)
483                         if_info = curr->data;
484                 if(if_info != NULL)
485                         if ( g_ascii_strcasecmp(if_info->name,name) == 0)
486                                 {
487                                 return if_info;
488                                 }
489                 ifn++;
490                 }
491         }
492 return NULL;
493 }
494
495 /*
496  * Returns the ASCII string of a key given the key bytes
497  */
498 gchar*
499 airpcap_get_key_string(AirpcapKey key)
500 {
501 unsigned int j = 0;
502 unsigned int l = 0;
503 gchar *dst,*src;
504
505 src = NULL;
506
507 if(key.KeyType == AIRPCAP_KEYTYPE_WEP)
508         {
509         if(key.KeyLen != 0)
510             {
511         /* Allocate the string used to store the ASCII representation of the WEP key */
512         dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
513         /* Make sure that the first char is '\0' in order to make g_strlcat() work */
514         dst[0]='\0';
515         
516             for(j = 0; j < key.KeyLen; j++)
517                     {
518                     src = g_strdup_printf("%.2x\0", key.KeyData[j]);
519                     /*
520              * XXX - use g_strconcat() instead ??? 
521              */         
522                 l = g_strlcat(dst,src,WEP_KEY_MAX_CHAR_SIZE+1);
523                 }
524         g_free(src);
525         }
526         }
527
528 return dst;
529 }
530
531 /*
532  * Used to retrieve the airpcap_if_info_t of the selected interface given the
533  * description (that is the entry of the combo box).
534  */
535 gpointer get_airpcap_if_from_description(GList* if_list, const gchar* description)
536 {
537 unsigned int ifn;
538 GList* curr;
539 airpcap_if_info_t* if_info;
540
541 ifn = 0;
542 if(if_list != NULL)
543         {
544         while( ifn < g_list_length(if_list) )
545                 {
546                 curr = g_list_nth(if_list, ifn);
547
548                 if_info = NULL;
549                 if(curr != NULL)
550                         if_info = curr->data;
551                 if(if_info != NULL)
552                         if ( g_ascii_strcasecmp(if_info->description,description) == 0)
553                                 {
554                                 return if_info;
555                                 }
556                 ifn++;
557                 }
558         }
559 return NULL;
560 }
561
562 /*
563  * Used to retrieve the two chars string from interface
564  */
565 gchar*
566 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
567 {
568         gchar* number;
569         guint n;
570         int a;
571
572         a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
573     
574     /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
575      * Otherwise, check if it is the "Any" adapter...
576      */
577      if(a == 0)
578           {
579           if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
580                number = g_strdup_printf("??");
581           else
582                number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
583           }
584      else
585           {
586           number = g_strdup_printf("%.2u\0",n);
587           }
588
589         return number;
590 }
591
592 /*
593  * Used to retrieve the two chars string from interface
594  */
595 gchar*
596 airpcap_get_if_string_number_from_description(gchar* description)
597 {
598         gchar* number;
599         gchar* pointer;
600
601         number = (gchar*)g_malloc(sizeof(gchar)*3);
602
603         pointer = g_strrstr(description,"#\0");
604
605         number[0] = *(pointer+1);
606         number[1] = *(pointer+2);
607         number[2] = '\0';
608
609         return number;
610 }
611
612 /*
613  * Returns the default airpcap interface of a list, NULL if list is empty
614  */
615 airpcap_if_info_t*
616 airpcap_get_default_if(GList* airpcap_if_list)
617 {
618 int ifn = 0;
619 GList* popdown_if_list = NULL;
620 GList* curr = NULL;
621
622         gchar* s;
623         airpcap_if_info_t* if_info = NULL;
624
625     if(prefs.capture_device != NULL)
626     {
627         s = g_strdup(get_if_name(prefs.capture_device));
628         if_info = get_airpcap_if_by_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
629         g_free(s);
630     }
631         return if_info;
632 }
633
634 /*
635  * Load the configuration for the specified interface
636  */
637 void
638 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
639 {
640 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
641 PAirpcapHandle ad;
642
643 if(if_info != NULL)
644         {
645         ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf);
646
647         if(ad)
648                 {
649                 /* Stop blinking (if it was blinkig!)*/
650                 if(if_info->blinking)
651                         {
652                         /* Turn on the light (if it was off) */
653                         if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
654                         }
655
656                 /* Apply settings... */
657                 airpcap_if_get_device_channel(ad,&(if_info->channel));
658                 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
659                 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
660                 airpcap_if_get_link_type(ad,&(if_info->linkType));
661                 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
662                 /* get the keys, if everything is ok, close the adapter */
663                 if(airpcap_if_load_keys(ad,if_info))
664                         airpcap_if_close(ad);
665
666                 if_info->saved = TRUE;
667                 }
668         else
669                 {
670                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
671                 }
672         }
673 }
674
675 /*
676  * Save the configuration for the specified interface
677  */
678 void
679 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
680 {
681 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
682 PAirpcapHandle ad;
683
684 if(if_info != NULL)
685         {
686         ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf);
687
688         if(ad)
689                 {
690                 /* Stop blinking (if it was blinkig!)*/
691                 if(if_info->blinking)
692                         {
693                         /* Turn on the light (if it was off) */
694                         if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
695                         }
696
697                 /* Apply settings... */
698                 airpcap_if_set_device_channel(ad,if_info->channel);
699                 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
700                 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
701                 airpcap_if_set_link_type(ad,if_info->linkType);
702                 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
703                 airpcap_if_save_keys(ad,if_info);
704
705                 /* ... and save them */
706                 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
707                         {
708                         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save Wireless configuration!!!\nRemember that in order to store the configuration in the registry you have to:\n\n- Close all the airpcap-based applications.\n- Be sure to have administrative privileges.");
709                         if_info->saved = FALSE;
710                         airpcap_if_close(ad);
711                         return;
712                         }
713
714                 if_info->saved = TRUE;
715                 airpcap_if_close(ad);
716                 }
717         else
718                 {
719                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
720                 }
721         }
722 }
723
724 /*
725  *  Used to dinamically load the airpcap library in order link it only when
726  *  it's present on the system
727  */
728 BOOL load_airpcap(void)
729 {
730  if((AirpcapLib =  LoadLibrary(TEXT("airpcap.dll"))) == NULL)
731  {
732   /* Report the error but go on */
733   return FALSE;
734  }
735  else
736  {
737   if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) return FALSE;
738   if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) return FALSE;
739   if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) return FALSE;
740   if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) return FALSE;
741   if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) return FALSE;
742   if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) return FALSE;
743   if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) return FALSE;
744   if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) return FALSE;
745   if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) return FALSE;
746   if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) return FALSE;
747   if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) return FALSE;
748   if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) return FALSE;
749   if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) return FALSE;
750   if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) return FALSE;
751   if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) return FALSE;
752   if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) return FALSE;
753   if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) return FALSE;
754   if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) return FALSE;
755   if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) return FALSE;
756   if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) return FALSE;
757   if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) return FALSE;
758   if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) return FALSE;
759   if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) return FALSE;
760   if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) return FALSE;
761   if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) return FALSE;
762   if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) return FALSE;
763   if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) return FALSE;
764   return TRUE;
765  }
766 }
767
768 #endif /* _WIN32 */