예제 #1
0
 public static IP_INTERFACE_INFO FromByteArray(Byte[] buffer)
 {
     unsafe
     {
         IP_INTERFACE_INFO rv = new IP_INTERFACE_INFO();
         int iNumAdapters     = 0;
         Marshal.Copy(buffer, 0, new IntPtr(&iNumAdapters), 4);
         NativeMethods.IP_ADAPTER_INDEX_MAP[] adapters = new NativeMethods.IP_ADAPTER_INDEX_MAP[iNumAdapters];
         rv.NumAdapters = iNumAdapters;
         rv.Adapter     = new NativeMethods.IP_ADAPTER_INDEX_MAP[iNumAdapters];
         int offset = sizeof(int);
         for (int i = 0; i < iNumAdapters; i++)
         {
             NativeMethods.IP_ADAPTER_INDEX_MAP map = new NativeMethods.IP_ADAPTER_INDEX_MAP();
             IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(map));
             Marshal.StructureToPtr(map, ptr, false);
             Marshal.Copy(buffer, offset, ptr, Marshal.SizeOf(map));
             map = (NativeMethods.IP_ADAPTER_INDEX_MAP)Marshal.PtrToStructure(ptr, typeof(NativeMethods.IP_ADAPTER_INDEX_MAP));
             Marshal.FreeHGlobal(ptr);
             rv.Adapter[i] = map;
             offset       += Marshal.SizeOf(map);
         }
         return(rv);
     }
 }
예제 #2
0
 public static bool IpReleaseAddress(NativeMethods.IP_ADAPTER_INDEX_MAP adapter)
 {
     if (NativeMethods.IpReleaseAddress(ref adapter) == NativeMethods.ERROR_SUCCESS)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }