c++ - DeleteIPAddress 和 AddIpAddress 问题

标签 c++ c windows winapi networking

我试着用这个函数编写添加ip地址的程序

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

我添加了,但是怎么删除呢。 DeleteIPAddress 将 NTEContext 作为参数我如何在 MSDN 中获取它,他们写道它由 AddIPAddress 函数返回但是当我第二次使用相同的 ip 地址调用它时它返回错误 2. 怎么办?

我可以在cmd中使用Ipconfig命令查看添加的ip地址,可能还有其他方法可以手动查看或删除它

最佳答案

你不能这样做。来自 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.

添加地址的生命周期如图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.

关于c++ - DeleteIPAddress 和 AddIpAddress 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4147405/

相关文章:

没有模板参数的 C++ 模板?

c++ - 链表的循环遍历

windows - 如何为较低的过滤磁盘驱动程序的内部设备控制请求正确注册完成例程?

windows - Windows 上的 PCSC-Lite 代码

c# - 扩展 Win 7 (Aero) 绘制其默认窗口和控件的方式

c++ STL库这些带下划线的方法是什么?

c++ - 编译嵌套参数包代码时出现 gcc 段错误

c - 在我自己的 C shell 中管道

c - 向子进程发送信号时出现问题

c - windows c 中的 sha-1 实现