简体   繁体   中英

DeleteIPAddress and AddIpAddress Problem

i tried to write program adding ip address using this function

 
DWORD AddIPAddress(
  __in   IPAddr Address,
  __in   IPMask IpMask,
  __in   DWORD IfIndex,
  __out  PULONG NTEContext,
  __out  PULONG NTEInstance
);

I have added it but how can I delete it. DeleteIPAddress takes NTEContext as Parameter how can i get it in MSDN they write it is returned by AddIPAddress function but when i call it for the second time with the same ip address it returns an error 2. What to do?

I can view add ip addresses using Ipconfig command in cmd, may be there is some other method to view or delete it manually

You can't do this. From MSDN :

To use DeleteIPAddress , AddIPAddress must first be called to get the handle NTEContext . The previous procedure assumes that AddIPAddress has already been called somewhere in the code, and NTEContext has been saved and remains uncorrupted.

The lifetime of the added address is as shown here :

The AddIPAddress function is used to add a new IPv4 address entry on a local computer. The IPv4 address added by the AddIPAddress function is not persistent. The IPv4 address exists only as long as the adapter object exists. Restarting the computer destroys the IPv4 address, as does manually resetting the network interface card (NIC). Also, certain PnP events may destroy the address.

Use GetAdaptersInfo in order to gain IP_ADAPTER_INFO . IP_ADDR_STRING has a suitable context for DeleteIPAddress in IP_ADAPTER_INFO .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM