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