Changeset 6994 for trunk/src/iphlpapi/iphlpapi.cpp
- Timestamp:
- Oct 10, 2001, 7:38:38 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/iphlpapi/iphlpapi.cpp
r6989 r6994 1 /* $Id: iphlpapi.cpp,v 1. 2 2001-10-10 16:22:19phaller Exp $ */1 /* $Id: iphlpapi.cpp,v 1.3 2001-10-10 17:37:44 phaller Exp $ */ 2 2 /* 3 3 * IPHLPAPI library … … 18 18 #include <winversion.h> 19 19 20 #include <string.h> 21 20 22 #include "iphlpapi.h" 21 23 22 24 ODINDEBUGCHANNEL(IPHLPAPI-IPHLPAPI) 25 26 27 /**************************************************************************** 28 * module global variables 29 ****************************************************************************/ 30 31 static PIP_ADAPTER_INFO pipAdapters = NULL; 32 33 34 //****************************************************************************** 35 //****************************************************************************** 36 static void i_initializeAdapterInformation(void) 37 { 38 // @@@PH 39 // yet a fake to test some app 40 pipAdapters = (PIP_ADAPTER_INFO)malloc (sizeof (IP_ADAPTER_INFO) ); 41 42 memset(pipAdapters, 0, sizeof( IP_ADAPTER_INFO )); 43 pipAdapters->Next = NULL; 44 pipAdapters->ComboIndex = 1; 45 strcpy(pipAdapters->AdapterName, "ODIN IPHLPAPI Test Adapter"); 46 strcpy(pipAdapters->Description, "ODIN IPHLPAPI Test Adapter (faked information)"); 47 pipAdapters->AddressLength = 4; 48 pipAdapters->Address[0] = 127; 49 pipAdapters->Address[1] = 0; 50 pipAdapters->Address[2] = 0; 51 pipAdapters->Address[3] = 1; 52 pipAdapters->Index = 1; 53 pipAdapters->Type = 1; 54 pipAdapters->DhcpEnabled = 0; 55 56 static IP_ADDR_STRING iasLocalhost; 57 iasLocalhost.Next = NULL; 58 strcpy((char*)&iasLocalhost.IpAddress,"127.0.0.1"); 59 strcpy((char*)&iasLocalhost.IpMask, "255.0.0.0"); 60 iasLocalhost.Context = 0; 61 62 memcpy((char*)&pipAdapters->IpAddressList, (char*)&iasLocalhost, sizeof(iasLocalhost)); 63 pipAdapters->CurrentIpAddress = &pipAdapters->IpAddressList; 64 memcpy((char*)&pipAdapters->GatewayList, (char*)&iasLocalhost, sizeof(iasLocalhost)); 65 memset((char*)&pipAdapters->DhcpServer, 0, sizeof( IP_ADDR_STRING ) ); 66 pipAdapters->HaveWins = 0; 67 memset((char*)&pipAdapters->PrimaryWinsServer, 0, sizeof( IP_ADDR_STRING ) ); 68 memset((char*)&pipAdapters->SecondaryWinsServer, 0, sizeof( IP_ADDR_STRING ) ); 69 pipAdapters->LeaseObtained = 0; 70 pipAdapters->LeaseExpires = 0; 71 } 72 73 // copy over the whole list and advance the target pointer 74 static void i_copyIP_ADDRESS_STRING(PBYTE *ppTarget, PIP_ADDR_STRING pias) 75 { 76 while (pias) 77 { 78 memcpy(*ppTarget, pias, sizeof( IP_ADDR_STRING ) ); 79 *ppTarget += sizeof ( IP_ADDR_STRING ); 80 pias = pias->Next; 81 } 82 } 83 84 static DWORD i_sizeOfIP_ADAPTER_INFO(PIP_ADAPTER_INFO piai) 85 { 86 PIP_ADDR_STRING pias; 87 88 // check for sufficient space 89 DWORD dwRequired = sizeof( IP_ADAPTER_INFO ); 90 91 // follow the IP_ADDR_STRING lists 92 pias = &piai->IpAddressList; 93 while( pias ) 94 { 95 dwRequired += sizeof( IP_ADDR_STRING ); 96 pias = pias->Next; 97 } 98 99 pias = &piai->GatewayList; 100 while( pias ) 101 { 102 dwRequired += sizeof( IP_ADDR_STRING ); 103 pias = pias->Next; 104 } 105 106 pias = &piai->DhcpServer; 107 while( pias ) 108 { 109 dwRequired += sizeof( IP_ADDR_STRING ); 110 pias = pias->Next; 111 } 112 113 pias = &piai->PrimaryWinsServer; 114 while( pias ) 115 { 116 dwRequired += sizeof( IP_ADDR_STRING ); 117 pias = pias->Next; 118 } 119 120 pias = &piai->SecondaryWinsServer; 121 while( pias ) 122 { 123 dwRequired += sizeof( IP_ADDR_STRING ); 124 pias = pias->Next; 125 } 126 127 return dwRequired; 128 } 23 129 24 130 … … 29 135 PULONG, pOutBufLen) 30 136 { 31 dprintf(("GetAdaptersInfo not implemented")); 32 33 static PIP_ADAPTER_INFO pipAdapters = NULL; 34 static ULONG ulAdaptersSize = 0; 137 dprintf(("GetAdaptersInfo incorrectly implemented")); 138 139 if (NULL == pOutBufLen) 140 return ERROR_INVALID_PARAMETER; 141 142 // verify first block of memory to write to 143 if (IsBadWritePtr(pAdapterInfo, 4)) 144 return ERROR_INVALID_PARAMETER; 35 145 36 146 if (NULL == pipAdapters) 37 147 { 38 148 // gather the information and save it 149 i_initializeAdapterInformation(); 39 150 40 151 // determine number of IP adapters (interfaces) in the system … … 43 154 } 44 155 156 if (NULL == pipAdapters) 157 return ERROR_NO_DATA; 158 45 159 // OK, just copy over the information as far as possible 160 LONG lSpaceLeft = *pOutBufLen; 161 PBYTE pTarget = (PBYTE)pAdapterInfo; 162 PIP_ADAPTER_INFO pip; 163 164 // calculate overall required buffer size 165 DWORD dwRequiredBuffer = 0; 166 167 for( pip = pipAdapters ; pip ; pip = pip->Next ) 168 { 169 // check for sufficient space 170 dwRequiredBuffer += i_sizeOfIP_ADAPTER_INFO(pip); 171 } 172 173 for( pip = pipAdapters ; pip ; pip = pip->Next ) 174 { 175 // check for sufficient space 176 DWORD dwRequired = i_sizeOfIP_ADAPTER_INFO(pip); 177 178 if (lSpaceLeft - dwRequired > 0) 179 { 180 lSpaceLeft -= dwRequired; 181 182 // copy over the whole structure hierarchy 183 memcpy(pTarget, pip, sizeof( IP_ADAPTER_INFO )); 184 pTarget += sizeof( IP_ADAPTER_INFO ); 185 186 // @@@PH shall point to somewhere within the current buffer 187 pip->CurrentIpAddress = (PIP_ADDR_STRING)pTarget; 188 189 i_copyIP_ADDRESS_STRING(&pTarget, &pip->IpAddressList); 190 i_copyIP_ADDRESS_STRING(&pTarget, &pip->GatewayList); 191 i_copyIP_ADDRESS_STRING(&pTarget, &pip->DhcpServer); 192 i_copyIP_ADDRESS_STRING(&pTarget, &pip->PrimaryWinsServer); 193 i_copyIP_ADDRESS_STRING(&pTarget, &pip->SecondaryWinsServer); 194 } 195 else 196 { 197 // return overall size of required buffer 198 *pOutBufLen = dwRequiredBuffer; 199 return ERROR_BUFFER_OVERFLOW; 200 } 201 } 46 202 47 203 return ERROR_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.