d65b06904ba1b5e1c642c908edf55d9cd489b72b
[metze/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 == NULL) {
391                 /* Airpcap.dll not available */
392                 *err = NO_AIRPCAP_INTERFACES_FOUND;
393                 return NULL;
394         }
395
396         if(!g_PAirpcapGetDeviceList(&devsList, err_str))
397         {
398                 /* No interfaces */
399                 *err = NO_AIRPCAP_INTERFACES_FOUND;
400                 return NULL;
401         }
402
403         /*
404          * Count the adapters
405          */
406         adListEntry = devsList;
407         n_adapts = 0;
408         while(adListEntry)
409         {
410                 n_adapts++;
411                 adListEntry = adListEntry->next;
412         }
413
414         if(n_adapts == 0)
415         {
416                 /* No interfaces, return il= NULL */
417                 g_PAirpcapFreeDeviceList(devsList);
418                 *err = NO_AIRPCAP_INTERFACES_FOUND;
419                 return il;
420         }
421
422         /*
423          * Insert the adapters in our list
424          */
425         adListEntry = devsList;
426         for(i = 0; i < n_adapts; i++)
427         {
428                 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
429         il = g_list_append(il, if_info);
430
431                 adListEntry = adListEntry->next;
432         }
433
434         g_PAirpcapFreeDeviceList(devsList);
435
436         return il;
437 }
438
439 /*
440  * Used to retrieve the name of the interface given the description
441  * (the name is used in AirpcapOpen, the description is put in the combo box)
442  */
443 gchar* get_airpcap_name_from_description(GList* if_list, gchar* description)
444 {
445 unsigned int ifn;
446 GList* curr;
447 airpcap_if_info_t* if_info;
448
449 ifn = 0;
450 if(if_list != NULL)
451         {
452         while( ifn < g_list_length(if_list) )
453                 {
454                 curr = g_list_nth(if_list, ifn);
455
456                 if_info = NULL;
457                 if(curr != NULL)
458                         if_info = curr->data;
459                 if(if_info != NULL)
460                         if ( g_ascii_strcasecmp(if_info->description,description) == 0)
461                                 {
462                                 return if_info->name;
463                                 }
464                 ifn++;
465                 }
466         }
467 return NULL;
468 }
469
470 /*
471  * Used to retrieve the interface given the name
472  * (the name is used in AirpcapOpen)
473  */
474 airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name)
475 {
476 unsigned int ifn;
477 GList* curr;
478 airpcap_if_info_t* if_info;
479
480 ifn = 0;
481 if(if_list != NULL)
482         {
483         while( ifn < g_list_length(if_list) )
484                 {
485                 curr = g_list_nth(if_list, ifn);
486
487                 if_info = NULL;
488                 if(curr != NULL)
489                         if_info = curr->data;
490                 if(if_info != NULL)
491                         if ( g_ascii_strcasecmp(if_info->name,name) == 0)
492                                 {
493                                 return if_info;
494                                 }
495                 ifn++;
496                 }
497         }
498 return NULL;
499 }
500
501 /*
502  * Returns the ASCII string of a key given the key bytes
503  */
504 gchar*
505 airpcap_get_key_string(AirpcapKey key)
506 {
507 unsigned int j = 0;
508 unsigned int l = 0;
509 gchar *dst,*src;
510
511 src = NULL;
512
513 if(key.KeyType == AIRPCAP_KEYTYPE_WEP)
514         {
515         if(key.KeyLen != 0)
516             {
517         /* Allocate the string used to store the ASCII representation of the WEP key */
518         dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
519         /* Make sure that the first char is '\0' in order to make g_strlcat() work */
520         dst[0]='\0';
521         
522             for(j = 0; j < key.KeyLen; j++)
523                     {
524                     src = g_strdup_printf("%.2x\0", key.KeyData[j]);
525                     /*
526              * XXX - use g_strconcat() instead ??? 
527              */         
528                 l = g_strlcat(dst,src,WEP_KEY_MAX_CHAR_SIZE+1);
529                 }
530         g_free(src);
531         }
532         }
533
534 return dst;
535 }
536
537 /*
538  * Used to retrieve the airpcap_if_info_t of the selected interface given the
539  * description (that is the entry of the combo box).
540  */
541 gpointer get_airpcap_if_from_description(GList* if_list, const gchar* description)
542 {
543 unsigned int ifn;
544 GList* curr;
545 airpcap_if_info_t* if_info;
546
547 ifn = 0;
548 if(if_list != NULL)
549         {
550         while( ifn < g_list_length(if_list) )
551                 {
552                 curr = g_list_nth(if_list, ifn);
553
554                 if_info = NULL;
555                 if(curr != NULL)
556                         if_info = curr->data;
557                 if(if_info != NULL)
558                         if ( g_ascii_strcasecmp(if_info->description,description) == 0)
559                                 {
560                                 return if_info;
561                                 }
562                 ifn++;
563                 }
564         }
565 return NULL;
566 }
567
568 /*
569  * Used to retrieve the two chars string from interface
570  */
571 gchar*
572 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
573 {
574         gchar* number;
575         guint n;
576         int a;
577
578         a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
579     
580     /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
581      * Otherwise, check if it is the "Any" adapter...
582      */
583      if(a == 0)
584           {
585           if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
586                number = g_strdup_printf("??");
587           else
588                number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
589           }
590      else
591           {
592           number = g_strdup_printf("%.2u\0",n);
593           }
594
595         return number;
596 }
597
598 /*
599  * Used to retrieve the two chars string from interface
600  */
601 gchar*
602 airpcap_get_if_string_number_from_description(gchar* description)
603 {
604         gchar* number;
605         gchar* pointer;
606
607         number = (gchar*)g_malloc(sizeof(gchar)*3);
608
609         pointer = g_strrstr(description,"#\0");
610
611         number[0] = *(pointer+1);
612         number[1] = *(pointer+2);
613         number[2] = '\0';
614
615         return number;
616 }
617
618 /*
619  * Returns the default airpcap interface of a list, NULL if list is empty
620  */
621 airpcap_if_info_t*
622 airpcap_get_default_if(GList* airpcap_if_list)
623 {
624 int ifn = 0;
625 GList* popdown_if_list = NULL;
626 GList* curr = NULL;
627
628         gchar* s;
629         airpcap_if_info_t* if_info = NULL;
630
631     if(prefs.capture_device != NULL)
632     {
633         s = g_strdup(get_if_name(prefs.capture_device));
634         if_info = get_airpcap_if_by_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
635         g_free(s);
636     }
637         return if_info;
638 }
639
640 /*
641  * Load the configuration for the specified interface
642  */
643 void
644 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
645 {
646 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
647 PAirpcapHandle ad;
648
649 if(if_info != NULL)
650         {
651         ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf);
652
653         if(ad)
654                 {
655                 /* Stop blinking (if it was blinkig!)*/
656                 if(if_info->blinking)
657                         {
658                         /* Turn on the light (if it was off) */
659                         if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
660                         }
661
662                 /* Apply settings... */
663                 airpcap_if_get_device_channel(ad,&(if_info->channel));
664                 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
665                 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
666                 airpcap_if_get_link_type(ad,&(if_info->linkType));
667                 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
668                 /* get the keys, if everything is ok, close the adapter */
669                 if(airpcap_if_load_keys(ad,if_info))
670                         airpcap_if_close(ad);
671
672                 if_info->saved = TRUE;
673                 }
674         else
675                 {
676                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
677                 }
678         }
679 }
680
681 /*
682  * Save the configuration for the specified interface
683  */
684 void
685 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
686 {
687 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
688 PAirpcapHandle ad;
689
690 if(if_info != NULL)
691         {
692         ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf);
693
694         if(ad)
695                 {
696                 /* Stop blinking (if it was blinkig!)*/
697                 if(if_info->blinking)
698                         {
699                         /* Turn on the light (if it was off) */
700                         if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
701                         }
702
703                 /* Apply settings... */
704                 airpcap_if_set_device_channel(ad,if_info->channel);
705                 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
706                 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
707                 airpcap_if_set_link_type(ad,if_info->linkType);
708                 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
709                 airpcap_if_save_keys(ad,if_info);
710
711                 /* ... and save them */
712                 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
713                         {
714                         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.");
715                         if_info->saved = FALSE;
716                         airpcap_if_close(ad);
717                         return;
718                         }
719
720                 if_info->saved = TRUE;
721                 airpcap_if_close(ad);
722                 }
723         else
724                 {
725                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
726                 }
727         }
728 }
729
730 /*
731  *  Used to dinamically load the airpcap library in order link it only when
732  *  it's present on the system
733  */
734 BOOL load_airpcap(void)
735 {
736  if((AirpcapLib =  LoadLibrary(TEXT("airpcap.dll"))) == NULL)
737  {
738   /* Report the error but go on */
739   return FALSE;
740  }
741  else
742  {
743   if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) return FALSE;
744   if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) return FALSE;
745   if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) return FALSE;
746   if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) return FALSE;
747   if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) return FALSE;
748   if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) return FALSE;
749   if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) return FALSE;
750   if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) return FALSE;
751   if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) return FALSE;
752   if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) return FALSE;
753   if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) return FALSE;
754   if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) return FALSE;
755   if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) return FALSE;
756   if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) return FALSE;
757   if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) return FALSE;
758   if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) return FALSE;
759   if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) return FALSE;
760   if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) return FALSE;
761   if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) return FALSE;
762   if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) return FALSE;
763   if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) return FALSE;
764   if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) return FALSE;
765   if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) return FALSE;
766   if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) return FALSE;
767   if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) return FALSE;
768   if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) return FALSE;
769   if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) return FALSE;
770   return TRUE;
771  }
772 }
773
774 #endif /* _WIN32 */