Example #1
0
        internal AirPcapKey(AirPcapUnmanagedStructures.AirpcapKey key)
        {
            Type = key.KeyType;

            Data = new byte[key.KeyData.Length];
            Array.Copy(key.KeyData, Data, Data.Length);
        }
Example #2
0
        /// <summary>
        /// Convert an array of keys into unmanaged memory
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static IntPtr KeysToIntPtr(List <AirPcapKey> value)
        {
            // allocate memory for the entire collection
            IntPtr pKeyCollection         = Marshal.AllocHGlobal(AirPcapDevice.KeyCollectionSize(value.Count));
            var    pKeyCollectionPosition = pKeyCollection;

            // build the collection struct
            var collection = new AirPcapUnmanagedStructures.AirpcapKeysCollection();

            collection.nKeys = (uint)value.Count;

            // convert this collection to unmanaged memory
            Marshal.StructureToPtr(collection, pKeyCollectionPosition, false);

            // advance the pointer
            pKeyCollectionPosition = new IntPtr(pKeyCollectionPosition.ToInt64() +
                                                Marshal.SizeOf(typeof(AirPcapUnmanagedStructures.AirpcapKeysCollection)));

            // write the keys to memory
            for (int x = 0; x < value.Count; x++)
            {
                var key = new AirPcapUnmanagedStructures.AirpcapKey();
                key.KeyType = value[x].Type;
                key.KeyLen  = (uint)value[x].Data.Length;

                // make sure we have the right size byte[], the fields in the structure passed to Marshal.StructureToPtr()
                // have to match the specified sizes or an exception will be thrown
                key.KeyData = new byte[AirPcapUnmanagedStructures.WepKeyMaxSize];
                Array.Copy(value[x].Data, key.KeyData, value[x].Data.Length);

                // copy the managed memory into the unmanaged memory
                Marshal.StructureToPtr(key, pKeyCollectionPosition, false);

                // advance the pointer
                pKeyCollectionPosition = new IntPtr(pKeyCollectionPosition.ToInt64() + Marshal.SizeOf(typeof(AirPcapUnmanagedStructures.AirpcapKey)));
            }

            return(pKeyCollection);
        }
Example #3
0
		/// <summary>
		/// Convert an array of keys into unmanaged memory
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		private static IntPtr KeysToIntPtr(List<AirPcapKey> value) {
			// allocate memory for the entire collection
			IntPtr pKeyCollection = Marshal.AllocHGlobal(AirPcapDevice.KeyCollectionSize(value.Count));
			var pKeyCollectionPosition = pKeyCollection;

			// build the collection struct
			var collection = new AirPcapUnmanagedStructures.AirpcapKeysCollection();
			collection.nKeys = (uint)value.Count;

			// convert this collection to unmanaged memory
			Marshal.StructureToPtr(collection, pKeyCollectionPosition, false);

			// advance the pointer
			pKeyCollectionPosition = new IntPtr(pKeyCollectionPosition.ToInt64() +
										Marshal.SizeOf(typeof(AirPcapUnmanagedStructures.AirpcapKeysCollection)));

			// write the keys to memory
			for (int x = 0; x < value.Count; x++) {
				var key = new AirPcapUnmanagedStructures.AirpcapKey();
				key.KeyType = value[x].Type;
				key.KeyLen = (uint)value[x].Data.Length;

				// make sure we have the right size byte[], the fields in the structure passed to Marshal.StructureToPtr()
				// have to match the specified sizes or an exception will be thrown
				key.KeyData = new byte[AirPcapUnmanagedStructures.WepKeyMaxSize];
				Array.Copy(value[x].Data, key.KeyData, value[x].Data.Length);

				// copy the managed memory into the unmanaged memory
				Marshal.StructureToPtr(key, pKeyCollectionPosition, false);

				// advance the pointer
				pKeyCollectionPosition = new IntPtr(pKeyCollectionPosition.ToInt64() + Marshal.SizeOf(typeof(AirPcapUnmanagedStructures.AirpcapKey)));
			}

			return pKeyCollection;
		}