DWORD dwNumNIC = 0;
IP_ADAPTER_INFO AdapterInfo[32]; // should someone has more than 32 adapters?
DWORD dwOutBufLen = sizeof(AdapterInfo);
CString strZ;
比如,本机是局域网的网关,有局域网址 192.168.0.1 ,还有拨号上网的动态 IP ,共计2个IP,根据各自的子网掩码就可以分辨哪些是局域网址、哪些是真实 internet 网址
有办法吗?
另外,我找了一些资料,好像 windows 和 linux 不同,多ip和操作系统内核相关的。
这是 windows ipconfig 的简单实现源码
http://www.codeproject.com/internet/netcfg.asp
这是 linux ifconfig 的源代码
http://freshmeat.net/projects/net-tools/
大家谁熟悉网络编程的,能不能把这两个都写成动态连接库,造福一下群众啊
addr.Format("%u", (unsigned int)((unsigned
char*)pHost->h_addr_list[i])[j]);
str += addr;
}
// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)
}
}