Add a macro that, for a given count of keys, returns the total size of

an AirpcapKeysCollection structure with that number of keys, and use it
instead of doing the calculation manually.

svn path=/trunk/; revision=47699
This commit is contained in:
Guy Harris 2013-02-17 03:45:06 +00:00
parent 806cb7224d
commit 8d7ffcc99b
3 changed files with 7 additions and 5 deletions

View File

@ -169,13 +169,13 @@ AirpcapMacAddress, *PAirpcapMacAddress;
/*!
\brief This structure is used to store a collection of WEP keys.
Note that the definition of the structure doesn't contain any key, so be careful to allocate a buffer
with the size of the key, like in the following example:
with the size of the set of keys, as per the following example:
\code
PAirpcapKeysCollection KeysCollection;
guint KeysCollectionSize;
KeysCollectionSize = sizeof(AirpcapKeysCollection) + NumKeys * sizeof(AirpcapKey);
KeysCollectionSize = AirpcapKeysCollectionSize(NumKeys);
KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
if(!KeysCollection)
@ -190,6 +190,8 @@ typedef struct _AirpcapKeysCollection
AirpcapKey Keys[0]; /* < Array of nKeys keys. */
} AirpcapKeysCollection, *PAirpcapKeysCollection;
#define AirpcapKeysCollectionSize(nKeys) (sizeof(AirpcapKeysCollection) + ((nKeys) * sizeof(AirpcapKey)))
/*!
\brief Packet header.

View File

@ -350,7 +350,7 @@ write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
/*
* Calculate the size of the keys collection
*/
KeysCollectionSize = (guint)(sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey));
KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
/*
* Allocate the collection
@ -449,7 +449,7 @@ write_wlan_driver_wep_keys_to_registry(GList* key_list)
/*
* Calculate the size of the keys collection
*/
KeysCollectionSize = (guint)(sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey));
KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
/*
* Allocate the collection

View File

@ -715,7 +715,7 @@ airpcap_add_keys_to_driver_from_list(GtkListStore *key_list_store, airpcap_if_in
/*
* Calculate the size of the keys collection
*/
KeysCollectionSize = (guint) (sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey));
KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
/*
* Allocate the collection