请问如何在程序里面给某个网卡添加一个IP地址

yurius 2003-08-25 12:10:14
如题
...全文
116 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
approach 2003-08-26
  • 打赏
  • 举报
回复
// you can try it....
#include <windows.h>
#include <IPExport.h>
#include <Iphlpapi.h>
#include <iostream.h>
#include <string.h>

int main(int argc, char* argv[])
{


IP_ADAPTER_INFO aaa[10];
ULONG sizeB = 10*sizeof(*aaa);
DWORD ttt =GetAdaptersInfo(aaa, &sizeB);

IPAddr Address = inet_addr("172.16.25.7"); //0xac102c07; //172.16.44.7
// IP address to add
IPMask IpMask = inet_addr("255.255.0.0"); //0xffff0000; //255.255.0.0
// subnet mask for IP address
DWORD IfIndex = aaa[0].Index; // index of adapter
ULONG NTEContext; // Net Table Entry context
ULONG NTEInstance; // Net Table Entry Instance
IP_ADAPTER_INFO AdapterInfo[100]; // buffer to receive data
ULONG size = sizeof(IP_ADAPTER_INFO)*100;



DWORD result = GetAdaptersInfo( AdapterInfo, &size );
if(result == ERROR_SUCCESS) {
result = AddIPAddress(Address, IpMask, IfIndex, &NTEContext, &NTEInstance );
cout << "adding address\n";
}
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
cout << (char *)lpMsgBuf << "\n";
cout << "Value returned: " << result << "\n";
cin >> result;
return 0;
}


kingzai 2003-08-25
  • 打赏
  • 举报
回复
http://support.microsoft.com/default.aspxscid=http://support.microsoft.com:80/support/kb/articles/Q199/7/49.ASP&NoWebContent=1
you should update platform sdk
yurius 2003-08-25
  • 打赏
  • 举报
回复
这个我知道,但用的时候不行,可以给个例子我吗,谢谢。
xiaoxx 2003-08-25
  • 打赏
  • 举报
回复
::AddIPAddress
::DeleteIPAddress
::GetIpAddrTable
::IpReleaseAddress
::IpRenewAddress

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧