/// <summary> /// Method called after making some changes to the current /// IP address, subnet mask, etc. This method notifies NDIS /// to rebind the adapter to all protocols, in effect causing /// the current registry settings to be applied rather than /// those which the current configuration represents. Once you /// have rebound an adapter, to get its new configuration, you /// must regenerate the list of adapters. Changes to things /// like the IP address, subnet mask, etc. are not immediately /// returned. /// </summary> public void Rebind() { NDIS.RebindInterface(this.Name); // refresh our adapter info, expecting a possible index change int index = Index; m_adapterInfo = GetAdapterInfo(ref index, Name); Index = index; }
public static void RebindInterface(string adapterName) { NDIS ndis = new NDIS(); ndis.Open(System.IO.FileAccess.ReadWrite, System.IO.FileShare.None); try { byte[] nameBytes = Encoding.Unicode.GetBytes(adapterName + "\0\0"); ndis.DeviceIoControl(IOCTL_NDIS_REBIND_ADAPTER, nameBytes, null); } finally { ndis.Dispose(); } }
/// <summary> /// Method called to unbind a given adapter. You might /// perform this operation before attempting to change /// *both* the protocol configuration of an adapter (IP, /// subnet, gateway), *and* the wireless configuration of /// the same adapter (WEP, SSID, etc.) To do that, first /// unbind the adapter, then change the settings, then /// bind the adapter (UnbindAdapter(), make changes, /// BindAdapter()). Once you have bound/unbound an /// adapter, to get its new configuration, you must /// regenerate the list of adapters. Changes to things /// like the IP address, subnet mask, etc. are not /// immediately returned. /// </summary> public void Unbind() { NDIS.UnbindInterface(this.Name); }
/// <summary> /// Method called on unbound adapter (maybe when handling /// changing *both* the IP/subnet/gateway *and* the wireless /// settings). This method notifies NDIS to bind the /// adapter to all protocols indicated in the registry, in /// effect causing the current registry settings to be /// applied rather than those which the adapter is currently /// using. Since we are binding, not *re*-binding the /// protocols, we are implying that the adapter is not /// currently bound to anything. When making this call, /// we must refresh any adapter list that we might have, /// to retrieve the current state of all adapters. /// Changes to things like the IP address, subnet mask, /// etc. are not immediately returned. /// </summary> public void Bind() { NDIS.BindInterface(this.Name); }