怎样获取本机的子网掩码?
请问用getadaptersinfo函数获取子网掩码,然后添加到一个Listbox控件中,应如何写?谢谢!
CString szMark;
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;
pAdapterInfo = ( IP_ADAPTER_INFO * ) malloc( sizeof( IP_ADAPTER_INFO ) );
ULONG ulOutBufLen;
ulOutBufLen = sizeof(IP_ADAPTER_INFO);
// 第一次调用GetAdapterInfo获取ulOutBufLen大小
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
{
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
}
if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
pAdapter = pAdapterInfo;
while (pAdapter)
{
szMark.Format(_T("%s"), CA2W(pAdapter-
>IpAddressList.IpMask.String));
pAdapter = pAdapter->Next;
}
}
将szMark值保存到listbox即可