![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Vista 32bit | IPHelper functions - to get IP and subnet mask Hi there, From IPHelper documentation it says that I need to use GetAdaptersAddress for Windows XP, Vista or later. It seems GetAdaptersAddress does not give me the IP and subnet mask info of the adapter. I used to use GetAdapterInfo() to get IP and Subnet mask. It looks like that GetAdapterInfo is still working on Vista, XP, but Microsoft IPHelper Doc says that I should use GetAdapterAddress instead. It is really confusing. So what are the proper API functions I should use for Vista or XP? Please help. |
My System Specs![]() |
| | #2 (permalink) |
| Vista 32bit | Re: IPHelper functions - to get IP and subnet mask I can get IP now, but subnet is not found. |
My System Specs![]() |
| | #3 (permalink) |
| Win7x64 | Re: IPHelper functions - to get IP and subnet mask Hi there, From IPHelper documentation it says that I need to use GetAdaptersAddress for Windows XP, Vista or later. It seems GetAdaptersAddress does not give me the IP and subnet mask info of the adapter. I used to use GetAdapterInfo() to get IP and Subnet mask. It looks like that GetAdapterInfo is still working on Vista, XP, but Microsoft IPHelper Doc says that I should use GetAdapterAddress instead. It is really confusing. So what are the proper API functions I should use for Vista or XP? Please help. |
My System Specs![]() |
| | #4 (permalink) |
| Vista 32bit | Re: IPHelper functions - to get IP and subnet mask Thanks. However, can I get the subnet mask (for an ip) from GetAdaptersAddress() (the similar way like in GetAdaptersInfo) ? I know that we can get subnet info from Winsock. It would be nice to get the subnet from GetAdaptersAddress(). |
My System Specs![]() |
| | #5 (permalink) |
| Vista 32bit | Re: IPHelper functions - to get IP and subnet mask GetAdaptersAddress() can get Network ID and Broadcast IP with Flags = GAA_FLAG_INCLUDE_PREFIX; From PIP_ADAPTER_PREFIX we should be able to get all IPs. and calculate the subnet mask. int nRet = WSAStartup(MAKEWORD(2, 2), &wsaData); if(nRet != 0) { m_pLogger->WriteLog(_T("%s, WSStartup() failed. Eorror: %d"), sMethodName, nRet); return ret; } //Get all the IP Address (Network IP, Adapter IP, Braodcast IP, for (i = 0, pIpAdapterPrefix = pCurrAddresses->FirstPrefix; pIpAdapterPrefix; i++, pIpAdapterPrefix = pIpAdapterPrefix->Next) { char szAddress[NI_MAXHOST]; char servInfo[NI_MAXSERV]; DWORD dwRet = getnameinfo(pIpAdapterPrefix->Address.lpSockaddr, pIpAdapterPrefix->Address.iSockaddrLength, szAddress, sizeof(szAddress), servInfo, NI_MAXSERV, NI_NUMERICHOST); if (dwRet != 0) { //"can't convert network format to presentation format"); } // szAddress will get IP in 0.0.0.0 format. if(i == 0) ipStartAddr = inet_addr(szAddress); if(i == 2) ipLastAddr = inet_addr(szAddress); } WSACleanup(); IPAddr ipMask = ntohl(ntohl(ipStartAddr) - ntohl(ipLastAddr) - 1); adapterInfo.m_sSubnetMask = ConvertIPAddrToIPString(ipMask); **** CString ConvertIPAddrToIPString(IPAddr ipAddress) { CString sIpString, sTemp; IPAddr IpTemp; int nbase[4] = {1, 256, 256*256, 256*256*256}; int nLen = 4; IpTemp = ntohl(ipAddress); for(int i = nLen-1; i >= 0; i--) { int nSubnetNumber; nSubnetNumber = IpTemp/nbase[i]; IpTemp = IpTemp%nbase[i]; if(i ==0) sTemp.Format(_T("%d"),nSubnetNumber); else sTemp.Format(_T("%d."),nSubnetNumber); sIpString += sTemp; } return sIpString; } |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| setting subnet mask and gateway | Vista networking & sharing | |||
| Iphelper, host process, appcrash, facebook, myspace | Vista General | |||
| IPHelper Error in Vista x64 | General Discussion | |||
| Vista VPN gets wrong subnet mask | Vista networking & sharing | |||
| Where can I see my IP and net mask? | Vista networking & sharing | |||