5 * Giorgio Tino <giorgio.tino@cacetech.com>
6 * Copyright (c) CACE Technologies, LLC 2006
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 2000 Gerald Combs
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.
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.
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.
42 #include <epan/packet.h>
43 #include <epan/prefs.h>
44 #include <epan/prefs-int.h>
45 #include "capture_ui_utils.h"
47 #include "simple_dialog.h"
50 #include "airpcap_loader.h"
53 * We load dinamically the dag library in order link it only when
54 * it's present on the system
56 static HMODULE AirpcapLib = NULL;
59 * Set to TRUE if the DLL was successfully loaded AND all functions
62 static gboolean AirpcapLoaded = FALSE;
64 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
65 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
66 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
67 static AirpcapOpenHandler g_PAirpcapOpen;
68 static AirpcapCloseHandler g_PAirpcapClose;
69 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
70 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
71 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
72 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
73 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
74 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
75 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
76 static AirpcapReadHandler g_PAirpcapRead;
77 static AirpcapGetStatsHandler g_PAirpcapGetStats;
78 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
79 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
80 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
81 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
82 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
83 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
84 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
85 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
86 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
87 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
88 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
89 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
90 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
91 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
93 /* Airpcap interface list */
94 GList *airpcap_if_list = NULL;
96 /* Airpcap current selected interface */
97 airpcap_if_info_t *airpcap_if_selected = NULL;
99 /* Airpcap current active interface */
100 airpcap_if_info_t *airpcap_if_active = NULL;
102 /* WLAN preferences pointer */
103 module_t *wlan_prefs = NULL;
105 /* Callback used by the load_wlan_keys() routine in order to read a WEP decryption key */
107 get_wep_key(pref_t *pref, gpointer ud _U_)
109 gchar *my_string = NULL;
110 keys_cb_data_t* user_data;
112 decryption_key_t* new_key;
114 /* Retrieve user data info */
115 user_data = (keys_cb_data_t*)ud;
117 if (g_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
119 my_string = g_strdup(*pref->varp.string);
121 if( my_string != NULL)
123 /* Key is added only if not null ... */
124 if( (g_strcasecmp(my_string,"") != 0) && (wep_key_is_valid(my_string)))
126 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
128 new_key->key = g_string_new(my_string);
131 new_key->bits = new_key->key->len * 4;
133 new_key->type = AIRPCAP_KEYTYPE_WEP;
135 new_key->ssid = NULL;
137 user_data->list = g_list_append(user_data->list,new_key);
138 user_data->number_of_keys++;
139 user_data->current_index++;
146 /* Callback used by the load_wlan_keys() routine in order to read a WPA decryption key */
148 get_wpa_key(pref_t *pref, gpointer ud _U_)
153 /* Callback used by the load_wlan_keys() routine in order to read a WPA2 decryption key */
155 get_wpa2_key(pref_t *pref, gpointer ud _U_)
160 /* Returs TRUE if the WEP key is valid, false otherwise */
162 wep_key_is_valid(char* key)
164 GString *new_key_string;
170 new_key_string = g_string_new(key);
172 if( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
174 g_string_free(new_key_string,FALSE);
177 if((new_key_string->len % 2) != 0)
179 g_string_free(new_key_string,FALSE);
182 for(i = 0; i < new_key_string->len; i++)
184 if(!g_ascii_isxdigit(new_key_string->str[i]))
186 g_string_free(new_key_string,FALSE);
191 g_string_free(new_key_string,FALSE);
195 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
197 set_wep_key(pref_t *pref, gpointer ud _U_)
199 gchar *my_string = NULL;
200 keys_cb_data_t* user_data;
201 gint wep_key_number = 0;
203 /* Retrieve user data info */
204 user_data = (keys_cb_data_t*)ud;
206 if (g_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
208 /* Ok, the pref we're gonna set is a wep_key ... but what number? */
209 sscanf(pref->name,"wep_key%d",&wep_key_number);
211 if(user_data->current_index < user_data->number_of_keys)
213 if(wep_key_number == (user_data->current_index+1))
215 my_string = g_strdup((char*)g_list_nth_data(user_data->list,user_data->current_index));
217 g_free((void *)*pref->varp.string);
218 *pref->varp.string = (void *)g_strdup(my_string);
223 else /* If the number of keys has been reduced somehow, we need to delete all the other keys
224 * (remember that the new ones have been probably overwritten)
227 g_free((void *)*pref->varp.string);
228 *pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
230 user_data->current_index++;
237 * Function used to read the Decryption Keys from the preferences and store them
238 * properly into the airpcap adapter.
241 load_wlan_wep_keys(airpcap_if_info_t* info_if)
243 keys_cb_data_t* user_data;
247 if(info_if == NULL) return FALSE;
249 /* Retrieve the wlan preferences */
250 wlan_prefs = prefs_find_module("wlan");
252 /* Allocate a structure used to keep infos between the callbacks */
253 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
255 /* Fill the structure */
256 user_data->list = NULL;
257 user_data->current_index = 0;
258 user_data->number_of_keys= 0; /* Still unknown */
260 /* Run the callback on each 802.11 preference */
261 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
263 /* Now the key list should be filled */
266 * Signal that we've changed things, and run the 802.11 dissector's
269 wlan_prefs->prefs_changed = TRUE;
271 prefs_apply(wlan_prefs);
273 write_wlan_wep_keys_to_regitry(info_if,user_data->list);
276 /* free the WEP key string */
277 for(i=0;i<g_list_length(user_data->list);i++)
279 g_free(g_list_nth(user_data->list,i)->data);
282 /* free the (empty) list */
283 g_list_free(user_data->list);
285 /* free the user_data structure */
292 * This function will tell the airpcap driver the key list to use
293 * This will be stored into the registry...
296 write_wlan_wep_keys_to_regitry(airpcap_if_info_t* info_if, GList* key_list)
301 PAirpcapKeysCollection KeysCollection;
302 ULONG KeysCollectionSize;
304 UINT keys_in_list = 0;
305 decryption_key_t* key_item = NULL;
307 keys_in_list = g_list_length(key_list);
310 * Save the encryption keys, if we have any of them
312 KeysCollectionSize = 0;
315 * Calculate the size of the keys collection
317 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
320 * Allocate the collection
322 KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
329 * Populate the key collection
331 KeysCollection->nKeys = keys_in_list;
333 for(i = 0; i < keys_in_list; i++)
335 KeysCollection->Keys[i].KeyType = AIRPCAP_KEYTYPE_WEP;
337 /* Retrieve the Item corresponding to the i-th key */
338 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
339 new_key = g_string_new(key_item->key->str);
341 KeysCollection->Keys[i].KeyLen = new_key->len / 2;
342 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
344 for(j = 0 ; j < new_key->len; j += 2)
346 s[0] = new_key->str[j];
347 s[1] = new_key->str[j+1];
349 KeyByte = (UCHAR)strtol(s, NULL, 16);
350 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
353 g_string_free(new_key,TRUE);
357 * Free the old adapter key collection!
359 if(info_if->keysCollection != NULL)
360 g_free(info_if->keysCollection);
363 * Set this collection ad the new one
365 info_if->keysCollection = KeysCollection;
366 info_if->keysCollectionSize = KeysCollectionSize;
369 * Configuration must be saved
371 info_if->saved = FALSE;
374 * Write down the changes to the registry
376 airpcap_save_selected_if_configuration(info_if);
382 * Function used to save to the preference file the Decryption Keys.
385 save_wlan_wep_keys(airpcap_if_info_t* info_if)
387 GList* key_list = NULL;
388 char* tmp_key = NULL;
389 guint keys_in_list,i;
390 keys_cb_data_t* user_data;
392 if(info_if == NULL) return FALSE;
394 /* Retrieve the wlan preferences */
395 wlan_prefs = prefs_find_module("wlan");
397 /* Allocate a structure used to keep infos between the callbacks */
398 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
400 /* Number of keys in key list */
401 keys_in_list = (info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
403 for(i=0; i<keys_in_list; i++)
405 /* Only if it is a WEP key... */
406 if(info_if->keysCollection->Keys[i].KeyType == AIRPCAP_KEYTYPE_WEP)
408 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
409 key_list = g_list_append(key_list,g_strdup(tmp_key));
414 /* Now we know the exact number of WEP keys in the list, so store it ... */
415 keys_in_list = g_list_length(key_list);
417 /* Fill the structure */
418 user_data->list = key_list;
419 user_data->current_index = 0;
420 user_data->number_of_keys= keys_in_list;
422 /* Retrieve the wlan preferences */
423 wlan_prefs = prefs_find_module("wlan");
425 /* Run the callback on each 802.11 preference */
426 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
428 /* Signal that we've changed things, and run the 802.11 dissector's
430 wlan_prefs->prefs_changed = TRUE;
432 /* Apply changes for the specified preference */
433 prefs_apply(wlan_prefs);
436 /* free the WEP key string */
437 for(i=0;i<g_list_length(user_data->list);i++)
439 g_free(g_list_nth(user_data->list,i)->data);
442 /* free the (empty) list */
443 g_list_free(user_data->list);
445 /* free the user_data structure */
452 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
453 * "get_airpcap_interface_list()".
456 cant_get_airpcap_if_list_error_message(const char *err_str)
458 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
462 * Airpcap wrapper, used to store the current settings for the selected adapter
465 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
467 if (!AirpcapLoaded) return FALSE;
468 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
472 * Airpcap wrapper, used to open an airpcap adapter
475 airpcap_if_open(PCHAR name, PCHAR err)
477 if (!AirpcapLoaded) return NULL;
478 return g_PAirpcapOpen(name,err);
482 * Airpcap wrapper, used to close an airpcap adapter
485 airpcap_if_close(PAirpcapHandle handle)
487 if (!AirpcapLoaded) return;
488 g_PAirpcapClose(handle);
492 * Airpcap wrapper, used to turn on the led of an airpcap adapter
495 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber)
497 if (!AirpcapLoaded) return FALSE;
498 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
502 * Airpcap wrapper, used to turn off the led of an airpcap adapter
505 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber)
507 if (!AirpcapLoaded) return FALSE;
508 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
512 * Airpcap wrapper, used to get the channel of an airpcap adapter
515 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch)
517 if (!AirpcapLoaded) return FALSE;
518 return g_PAirpcapGetDeviceChannel(ah,ch);
522 * Airpcap wrapper, used to set the channel of an airpcap adapter
525 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch)
527 if (!AirpcapLoaded) return FALSE;
528 return g_PAirpcapSetDeviceChannel(ah,ch);
532 * Airpcap wrapper, used to get the link type of an airpcap adapter
535 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
537 if (!AirpcapLoaded) return FALSE;
538 return g_PAirpcapGetLinkType(ah,lt);
542 * Airpcap wrapper, used to set the link type of an airpcap adapter
545 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
547 if (!AirpcapLoaded) return FALSE;
548 return g_PAirpcapSetLinkType(ah,lt);
552 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
555 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL fcs)
557 if (!AirpcapLoaded) return FALSE;
558 return g_PAirpcapGetFcsPresence(ah,fcs);
562 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
565 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL fcs)
567 if (!AirpcapLoaded) return FALSE;
568 return g_PAirpcapSetFcsPresence(ah,fcs);
572 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
575 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
577 if (!AirpcapLoaded) return FALSE;
578 return g_PAirpcapGetDecryptionState(ah,PEnable);
582 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
585 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
587 if (!AirpcapLoaded) return FALSE;
588 return g_PAirpcapSetDecryptionState(ah,Enable);
592 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
595 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
597 if (!AirpcapLoaded) return FALSE;
598 return g_PAirpcapGetFcsValidation(ah,val);
602 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
605 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
607 if (!AirpcapLoaded) return FALSE;
608 return g_PAirpcapSetFcsValidation(ah,val);
612 * Airpcap wrapper, used to save the settings for the selected_if
615 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
617 if (!AirpcapLoaded) return FALSE;
618 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
622 * Airpcap wrapper, used to save the settings for the selected_if
625 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize)
627 if (!AirpcapLoaded) return FALSE;
628 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
632 * This function will create a new airpcap_if_info_t using a name and a description
635 airpcap_if_info_new(char *name, char *description)
638 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
640 airpcap_if_info_t *if_info;
642 if_info = g_malloc(sizeof (airpcap_if_info_t));
643 if_info->name = g_strdup(name);
644 if (description == NULL)
645 if_info->description = NULL;
647 if_info->description = g_strdup(description);
648 if_info->ip_addr = NULL;
649 if_info->loopback = FALSE;
651 /* Probably I have to switch on the leds!!! */
652 ad = airpcap_if_open(if_info->name, ebuf);
655 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
656 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
657 airpcap_if_get_link_type(ad,&(if_info->linkType));
658 airpcap_if_get_device_channel(ad,&(if_info->channel));
659 airpcap_if_turn_led_on(ad, 0);
660 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
662 if_info->blinking = FALSE;
663 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
665 /* get the keys, if everything is ok, close the adapter */
666 if(airpcap_if_load_keys(ad,if_info))
667 airpcap_if_close(ad);
673 * Function used to load the WEP keys for a selected interface
676 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
678 if (!if_info) return FALSE;
680 if_info->keysCollectionSize = 0;
681 if_info->keysCollection = NULL;
683 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
685 if(if_info->keysCollectionSize == 0)
687 if_info->keysCollection = NULL;
688 airpcap_if_close(ad);
692 if_info->keysCollection = (PAirpcapKeysCollection)malloc(if_info->keysCollectionSize);
693 if(!if_info->keysCollection)
695 if_info->keysCollectionSize = 0;
696 if_info->keysCollection = NULL;
697 airpcap_if_close(ad);
701 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
704 airpcap_if_close(ad);
709 * Function used to save the WEP keys for a selected interface
712 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
714 if (!if_info || !AirpcapLoaded) return;
716 if(if_info->keysCollection != NULL)
717 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
721 * Callback used to free an instance of airpcap_if_info_t
724 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
726 airpcap_if_info_t *if_info = data;
728 if (if_info->name != NULL)
729 g_free(if_info->name);
731 if (if_info->description != NULL)
732 g_free(if_info->description);
734 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
735 if(if_info->keysCollection != NULL)
736 g_free(if_info->keysCollection);
738 if(if_info->ip_addr != NULL)
739 g_slist_free(if_info->ip_addr);
746 * Function used to free the airpcap interface list
749 free_airpcap_interface_list(GList *if_list)
751 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
752 g_list_free(if_list);
757 * This function will use the airpcap.dll to find all the airpcap devices.
758 * Will return null if no device is found.
761 get_airpcap_interface_list(int *err, char *err_str)
764 airpcap_if_info_t *if_info;
766 AirpcapDeviceDescription *devsList, *adListEntry;
769 *err = NO_AIRPCAP_INTERFACES_FOUND;
771 if(!AirpcapLoaded || !g_PAirpcapGetDeviceList(&devsList, err_str))
773 /* No interfaces, return il = NULL; */
780 adListEntry = devsList;
785 adListEntry = adListEntry->next;
790 /* No interfaces, return il= NULL */
791 g_PAirpcapFreeDeviceList(devsList);
796 * Insert the adapters in our list
798 adListEntry = devsList;
799 for(i = 0; i < n_adapts; i++)
801 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
802 il = g_list_append(il, if_info);
804 adListEntry = adListEntry->next;
807 g_PAirpcapFreeDeviceList(devsList);
813 * Used to retrieve the name of the interface given the description
814 * (the name is used in AirpcapOpen, the description is put in the combo box)
816 gchar* get_airpcap_name_from_description(GList* if_list, gchar* description)
820 airpcap_if_info_t* if_info;
825 while( ifn < g_list_length(if_list) )
827 curr = g_list_nth(if_list, ifn);
831 if_info = curr->data;
833 if ( g_ascii_strcasecmp(if_info->description,description) == 0)
835 return if_info->name;
844 * Used to retrieve the interface given the name
845 * (the name is used in AirpcapOpen)
847 airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name)
851 airpcap_if_info_t* if_info;
856 while( ifn < g_list_length(if_list) )
858 curr = g_list_nth(if_list, ifn);
862 if_info = curr->data;
864 if ( g_ascii_strcasecmp(if_info->name,name) == 0)
875 * Returns the ASCII string of a key given the key bytes
878 airpcap_get_key_string(AirpcapKey key)
886 if(key.KeyType == AIRPCAP_KEYTYPE_WEP)
890 /* Allocate the string used to store the ASCII representation of the WEP key */
891 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
892 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
895 for(j = 0; j < key.KeyLen; j++)
897 src = g_strdup_printf("%.2x\0", key.KeyData[j]);
899 * XXX - use g_strconcat() or GStrings instead ???
901 l = g_strlcat(dst,src,WEP_KEY_MAX_CHAR_SIZE+1);
906 else if(key.KeyType == AIRPCAP_KEYTYPE_TKIP)
908 /* XXX - Add code here */
910 else if(key.KeyType == AIRPCAP_KEYTYPE_CCMP)
912 /* XXX - Add code here */
916 /* XXX - Add code here */
923 * Used to retrieve the airpcap_if_info_t of the selected interface given the
924 * description (that is the entry of the combo box).
926 gpointer get_airpcap_if_from_description(GList* if_list, const gchar* description)
930 airpcap_if_info_t* if_info;
935 while( ifn < g_list_length(if_list) )
937 curr = g_list_nth(if_list, ifn);
941 if_info = curr->data;
943 if ( g_ascii_strcasecmp(if_info->description,description) == 0)
954 * Used to retrieve the two chars string from interface
957 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
963 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
965 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
966 * Otherwise, check if it is the "Any" adapter...
970 if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
971 number = g_strdup_printf("??");
973 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
977 number = g_strdup_printf("%.2u\0",n);
984 * Used to retrieve the two chars string from interface
987 airpcap_get_if_string_number_from_description(gchar* description)
992 number = (gchar*)g_malloc(sizeof(gchar)*3);
994 pointer = g_strrstr(description,"#\0");
996 number[0] = *(pointer+1);
997 number[1] = *(pointer+2);
1004 * Returns the default airpcap interface of a list, NULL if list is empty
1007 airpcap_get_default_if(GList* airpcap_if_list)
1010 GList* popdown_if_list = NULL;
1014 airpcap_if_info_t* if_info = NULL;
1016 if(prefs.capture_device != NULL)
1018 s = g_strdup(get_if_name(prefs.capture_device));
1019 if_info = get_airpcap_if_by_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
1026 * Load the configuration for the specified interface
1029 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1031 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1036 ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf);
1040 /* Stop blinking (if it was blinkig!)*/
1041 if(if_info->blinking)
1043 /* Turn on the light (if it was off) */
1044 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1047 /* Apply settings... */
1048 airpcap_if_get_device_channel(ad,&(if_info->channel));
1049 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1050 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1051 airpcap_if_get_link_type(ad,&(if_info->linkType));
1052 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1053 /* get the keys, if everything is ok, close the adapter */
1054 if(airpcap_if_load_keys(ad,if_info))
1055 airpcap_if_close(ad);
1057 if_info->saved = TRUE;
1061 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1067 * Save the configuration for the specified interface
1070 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1072 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1077 ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf);
1081 /* Stop blinking (if it was blinkig!)*/
1082 if(if_info->blinking)
1084 /* Turn on the light (if it was off) */
1085 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1088 /* Apply settings... */
1089 airpcap_if_set_device_channel(ad,if_info->channel);
1090 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1091 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1092 airpcap_if_set_link_type(ad,if_info->linkType);
1093 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1094 airpcap_if_save_keys(ad,if_info);
1096 /* ... and save them */
1097 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1099 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.");
1100 if_info->saved = FALSE;
1101 airpcap_if_close(ad);
1105 if_info->saved = TRUE;
1106 airpcap_if_close(ad);
1110 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1116 * DECRYPTION KEYS FUNCTIONS
1119 * This function is used for DEBUG POURPOSES ONLY!!!
1122 print_key_list(GList* key_list)
1125 decryption_key_t* tmp;
1127 n = g_list_length(key_list);
1129 g_print("\n\n********* KEY LIST **********\n\n");
1131 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1133 for(i =0; i < n; i++)
1135 g_print("[%d] :\n",i+1);
1136 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1137 g_print("KEY : %s\n",tmp->key->str);
1139 g_print("BITS: %d\n",tmp->bits);
1141 if(tmp->type == AIRPCAP_KEYTYPE_WEP)
1142 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1143 else if(tmp->type == AIRPCAP_KEYTYPE_TKIP)
1144 g_print("TYPE: %s\n",AIRPCAP_WPA_KEY_STRING);
1145 else if(tmp->type == AIRPCAP_KEYTYPE_CCMP)
1146 g_print("TYPE: %s\n",AIRPCAP_WPA2_KEY_STRING);
1148 g_print("TYPE: %s\n","???");
1150 g_print("SSID: %s\n",(tmp->ssid != NULL) ? tmp->ssid->str : "---");
1154 g_print("\n*****************************\n\n");
1158 * Retrieves a GList of decryption_key_t structures containing infos about the
1159 * keys for the given adapter... returns NULL if no keys are found.
1162 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1165 char* tmp_key = NULL;
1166 guint i,keys_in_list = 0;
1169 decryption_key_t *new_key = NULL;
1170 GList *key_list = NULL;
1172 /* Number of keys in key list */
1173 if(info_if->keysCollectionSize != 0)
1174 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1178 for(i=0; i<keys_in_list; i++)
1180 /* Different things to do depending on the key type */
1181 if(info_if->keysCollection->Keys[i].KeyType == AIRPCAP_KEYTYPE_WEP)
1183 /* allocate memory for the new key item */
1184 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1186 /* fill the fields */
1188 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1189 new_key->key = g_string_new(tmp_key);
1193 new_key->bits = new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an exadecimal number) */
1195 /* SSID not used in WEP keys */
1196 new_key->ssid = NULL;
1198 /* TYPE (WEP in this case) */
1199 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1201 /* Append the new element in the list */
1202 key_list = g_list_append(key_list,(gpointer)new_key);
1204 else if(info_if->keysCollection->Keys[i].KeyType == AIRPCAP_KEYTYPE_TKIP)
1206 /* XXX - Not supported yet */
1208 else if(info_if->keysCollection->Keys[i].KeyType == AIRPCAP_KEYTYPE_CCMP)
1210 /* XXX - Not supported yet */
1218 * Returns the list of the decryption keys specified for wireshark, NULL if
1222 get_wireshark_keys()
1224 keys_cb_data_t* wep_user_data = NULL;
1225 keys_cb_data_t* wpa_user_data = NULL;
1226 keys_cb_data_t* wpa2_user_data= NULL;
1230 GList* final_list = NULL;
1231 GList* wep_final_list = NULL;
1232 GList* wpa_final_list = NULL;
1233 GList* wpa2_final_list = NULL;
1235 /* Retrieve the wlan preferences */
1236 wlan_prefs = prefs_find_module("wlan");
1238 /* Allocate a structure used to keep infos between the callbacks */
1239 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1241 /* Fill the structure */
1242 wep_user_data->list = NULL;
1243 wep_user_data->current_index = 0;
1244 wep_user_data->number_of_keys= 0; /* Still unknown */
1246 /* Run the callback on each 802.11 preference */
1247 /* XXX - Right now, only WEP keys will be loaded */
1248 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1249 prefs_pref_foreach(wlan_prefs, get_wpa_key, (gpointer)wpa_user_data);
1250 prefs_pref_foreach(wlan_prefs, get_wpa2_key, (gpointer)wpa2_user_data);
1252 /* Copy the list field in the user data structure pointer into the final_list */
1253 if(wep_user_data != NULL) wep_final_list = wep_user_data->list;
1254 if(wpa_user_data != NULL) wpa_final_list = wpa_user_data->list;
1255 if(wpa2_user_data != NULL) wpa2_final_list = wpa2_user_data->list;
1257 /* XXX - Merge the three lists!!!!! */
1258 final_list = wep_final_list;
1260 /* free the wep_user_data structure */
1261 g_free(wep_user_data);
1262 /* free the wpa_user_data structure */
1263 g_free(wpa_user_data);
1264 /* free the wpa2_user_data structure */
1265 g_free(wpa2_user_data);
1271 * Merges two lists of keys and return a newly created GList. If a key is
1272 * found multiple times, it will just appear once!
1273 * list1 and list 2 pointer will have to be freed manually if needed!!!
1274 * If the total number of keys exceeeds the maximum number allowed,
1275 * exceeding keys will be discarded...
1278 merge_key_list(GList* list1, GList* list2)
1282 decryption_key_t *dk1=NULL,
1286 GList* merged_list = NULL;
1288 if( (list1 == NULL) && (list2 == NULL) )
1294 n2 = g_list_length(list2);
1298 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1299 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1301 new_dk->bits = dk2->bits;
1302 new_dk->type = dk2->type;
1303 new_dk->key = g_string_new(dk2->key->str);
1304 if(dk2->ssid != NULL)
1305 new_dk->ssid = g_string_new(dk2->ssid->str);
1307 new_dk->ssid = NULL;
1309 /* Check the total length of the merged list */
1310 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1311 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1314 else if(list2 == NULL)
1316 n1 = g_list_length(list1);
1321 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1322 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1324 new_dk->bits = dk1->bits;
1325 new_dk->type = dk1->type;
1326 new_dk->key = g_string_new(dk1->key->str);
1327 if(dk1->ssid != NULL)
1328 new_dk->ssid = g_string_new(dk1->ssid->str);
1330 new_dk->ssid = NULL;
1332 /* Check the total length of the merged list */
1333 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1334 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1339 n1 = g_list_length(list1);
1340 n2 = g_list_length(list2);
1342 /* Copy the whole list1 into merged_list */
1345 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1346 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
1348 new_dk->bits = dk1->bits;
1349 new_dk->type = dk1->type;
1350 new_dk->key = g_string_new(dk1->key->str);
1352 if(dk1->ssid != NULL)
1353 new_dk->ssid = g_string_new(dk1->ssid->str);
1355 new_dk->ssid = NULL;
1357 /* Check the total length of the merged list */
1358 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1359 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1362 /* Look for keys that are present in list2 but aren't in list1 yet...
1363 * Add them to merged_list
1367 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1369 if(!key_is_in_list(dk2,merged_list))
1371 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1373 new_dk->bits = dk2->bits;
1374 new_dk->type = dk2->type;
1375 new_dk->key = g_string_new(dk2->key->str);
1376 if(dk2->ssid != NULL)
1377 new_dk->ssid = g_string_new(dk2->ssid->str);
1379 new_dk->ssid = NULL;
1381 /* Check the total length of the merged list */
1382 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1383 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1392 * Use this function to free a key list.
1395 free_key_list(GList *list)
1398 decryption_key_t *curr_key;
1403 n = g_list_length(list);
1405 for(i = 0; i < n; i++)
1407 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
1409 /* Free all the strings */
1410 if(curr_key->key != NULL)
1411 g_string_free(curr_key->key,TRUE);
1413 if(curr_key->ssid != NULL)
1414 g_string_free(curr_key->ssid,TRUE);
1416 /* free the decryption_key_t structure*/
1429 * If the given key is contained in the list, returns TRUE.
1430 * Returns FALSE otherwise.
1433 key_is_in_list(decryption_key_t *dk,GList *list)
1436 decryption_key_t* curr_key = NULL;
1437 gboolean found = FALSE;
1439 if( (list == NULL) || (dk == NULL) )
1442 n = g_list_length(list);
1447 for(i = 0; i < n; i++)
1449 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
1450 if(keys_are_equals(dk,curr_key))
1458 * Returns TRUE if keys are equals, FALSE otherwise
1461 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
1463 if((k1==NULL) || (k2==NULL))
1466 if( g_string_equal(k1->key,k2->key) &&
1467 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
1468 k1->type == k2->type)
1470 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
1471 if((k1->ssid == NULL) && (k2->ssid == NULL))
1474 /* Check if one of them is null and one is not... */
1475 if((k1->ssid == NULL) || (k2->ssid == NULL))
1478 /* If they are not null, they must share the same ssid */
1479 return g_string_equal(k1->ssid,k2->ssid);
1482 /* Some field is not equal ... */
1487 * Tests if two collection of keys are equal or not, to be considered equals, they have to
1488 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
1492 key_lists_are_equal(GList* list1, GList* list2)
1496 decryption_key_t *dk1=NULL,*dk2=NULL;
1498 n1 = g_list_length(list1);
1499 n2 = g_list_length(list2);
1501 if(n1 != n2) return FALSE;
1505 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
1506 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
1508 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
1515 test_if_on(pref_t *pref, gpointer ud _U_)
1520 /* Retrieve user data info */
1521 is_on = (gboolean*)ud;
1524 if (g_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
1526 number = *pref->varp.boolp;
1528 if(number) *is_on = TRUE;
1529 else *is_on = FALSE;
1537 * Returns TRUE if the Wireshark decryption is active, false otherwise
1540 wireshark_decryption_on()
1544 /* Retrieve the wlan preferences */
1545 wlan_prefs = prefs_find_module("wlan");
1547 /* Run the callback on each 802.11 preference */
1548 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
1554 * Returns TRUE if the AirPcap decryption is active, false otherwise
1557 airpcap_decryption_on()
1559 gboolean is_on = FALSE;
1561 if(airpcap_if_selected != NULL)
1563 is_on = (gboolean)airpcap_if_selected->DecryptionOn;
1570 set_on_off(pref_t *pref, gpointer ud _U_)
1575 /* Retrieve user data info */
1576 is_on = (gboolean*)ud;
1578 if (g_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
1580 number = *pref->varp.boolp;
1582 g_free((void *)*pref->varp.boolp);
1584 *pref->varp.boolp = TRUE;
1586 *pref->varp.boolp = FALSE;
1594 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
1597 set_wireshark_decryption(gboolean on_off)
1603 /* Retrieve the wlan preferences */
1604 wlan_prefs = prefs_find_module("wlan");
1606 /* Run the callback on each 802.11 preference */
1607 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
1610 * Signal that we've changed things, and run the 802.11 dissector's
1613 wlan_prefs->prefs_changed = TRUE;
1615 prefs_apply(wlan_prefs);
1619 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
1622 set_airpcap_decryption(gboolean on_off)
1624 /* We need to directly access the .ddl functions here... */
1625 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1628 gboolean success = TRUE;
1632 airpcap_if_info_t* curr_if = NULL;
1634 n = g_list_length(airpcap_if_list);
1636 /* The same kind of settings should be propagated to all the adapters */
1637 /* Apply this change to all the adapters !!! */
1638 for(i = 0; i < n; i++)
1640 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
1642 if( curr_if != NULL )
1644 ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list,curr_if->description), ebuf);
1647 curr_if->DecryptionOn = (gboolean)on_off;
1648 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
1649 /* Save configuration for the curr_if */
1650 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1654 airpcap_if_close(ad);
1663 /* DYNAMIC LIBRARY LOADER */
1665 * Used to dynamically load the airpcap library in order link it only when
1666 * it's present on the system
1668 BOOL load_airpcap(void)
1670 if((AirpcapLib = LoadLibrary(TEXT("airpcap.dll"))) == NULL)
1672 /* Report the error but go on */
1677 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) return FALSE;
1678 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) return FALSE;
1679 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) return FALSE;
1680 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) return FALSE;
1681 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) return FALSE;
1682 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) return FALSE;
1683 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) return FALSE;
1684 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) return FALSE;
1685 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) return FALSE;
1686 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) return FALSE;
1687 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) return FALSE;
1688 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) return FALSE;
1689 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) return FALSE;
1690 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) return FALSE;
1691 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) return FALSE;
1692 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) return FALSE;
1693 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) return FALSE;
1694 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) return FALSE;
1695 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) return FALSE;
1696 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) return FALSE;
1697 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) return FALSE;
1698 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) return FALSE;
1699 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) return FALSE;
1700 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) return FALSE;
1701 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) return FALSE;
1702 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) return FALSE;
1703 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) return FALSE;
1704 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) return FALSE;
1705 AirpcapLoaded = TRUE;
1711 * Append the version of AirPcap with which we were compiled to a GString.
1714 get_compiled_airpcap_version(GString *str)
1716 g_string_append(str, "with AirPcap");
1720 * Append the version of AirPcap with which we we're running to a GString.
1723 get_runtime_airpcap_version(GString *str)
1725 guint vmaj, vmin, vrev, build;
1727 /* See if the DLL has been loaded successfully. Bail if it hasn't */
1728 if (AirpcapLoaded == FALSE) {
1729 g_string_append(str, "without AirPcap");
1733 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
1734 g_string_sprintfa(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,