Added some exports.
[reactos.git] / reactos / lib / iphlpapi / iphlpapi.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Winsock 2 IP Helper API DLL
4 * FILE: iphlpapi.c
5 * PURPOSE: DLL entry
6 * PROGRAMMERS: Robert Dickenson (robd@reactos.org)
7 * REVISIONS:
8 * RDD August 18, 2002 Created
9 */
10
11 #include <stdio.h>
12 #include <windows.h>
13 #include <tchar.h>
14 #include <time.h>
15
16 #include <iptypes.h>
17 #include <ipexport.h>
18 #include <iphlpapi.h>
19
20 #include "debug.h"
21 //#include "trace.h"
22
23 #ifdef __GNUC__
24 #define EXPORT STDCALL
25 #else
26 #define EXPORT CALLBACK
27 #endif
28
29 #ifdef DBG
30
31 /* See debug.h for debug/trace constants */
32 DWORD DebugTraceLevel = MAX_TRACE;
33
34 #endif /* DBG */
35
36 /* To make the linker happy */
37 //VOID STDCALL KeBugCheck (ULONG BugCheckCode) {}
38
39
40 BOOL
41 EXPORT
42 DllMain(HANDLE hInstDll,
43 ULONG dwReason,
44 PVOID Reserved)
45 {
46 //WSH_DbgPrint(MIN_TRACE, ("DllMain of iphlpapi.dll\n"));
47
48 switch (dwReason) {
49 case DLL_PROCESS_ATTACH:
50 /* Don't need thread attach notifications
51 so disable them to improve performance */
52 DisableThreadLibraryCalls(hInstDll);
53 break;
54
55 case DLL_THREAD_ATTACH:
56 break;
57
58 case DLL_THREAD_DETACH:
59 break;
60
61 case DLL_PROCESS_DETACH:
62 break;
63 }
64 return TRUE;
65 }
66
67
68 DWORD
69 WINAPI
70 AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance)
71 {
72 UNIMPLEMENTED
73 return 0L;
74 }
75
76
77 DWORD
78 WINAPI
79 SetIpNetEntry(PMIB_IPNETROW pArpEntry)
80 {
81 UNIMPLEMENTED
82 return 0L;
83 }
84
85 DWORD
86 WINAPI
87 CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
88 {
89 UNIMPLEMENTED
90 return 0L;
91 }
92
93
94 #ifdef __GNUC__
95
96 DWORD
97 WINAPI
98 GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
99 {
100 return 0;
101 }
102
103 DWORD
104 WINAPI
105 GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
106 {
107 return 0;
108 }
109
110 #endif
111
112
113 ////////////////////////////////////////////////////////////////////////////////
114
115 DWORD
116 WINAPI
117 GetNumberOfInterfaces(OUT PDWORD pdwNumIf)
118 {
119 DWORD result = NO_ERROR;
120 HKEY hKey;
121 LONG errCode;
122 int i = 0;
123
124 if (pdwNumIf == NULL) return ERROR_INVALID_PARAMETER;
125 *pdwNumIf = 0;
126 errCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, KEY_READ, &hKey);
127 if (errCode == ERROR_SUCCESS) {
128 DWORD dwSize;
129 errCode = RegQueryValueExW(hKey, L"Bind", NULL, NULL, NULL, &dwSize);
130 if (errCode == ERROR_SUCCESS) {
131 wchar_t* pData = (wchar_t*)malloc(dwSize * sizeof(wchar_t));
132 errCode = RegQueryValueExW(hKey, L"Bind", NULL, NULL, (LPBYTE)pData, &dwSize);
133 if (errCode == ERROR_SUCCESS) {
134 wchar_t* pStr = pData;
135 for (i = 0; *pStr != L'\0'; i++) {
136 pStr = pStr + wcslen(pStr) + 1; // next string
137 }
138 }
139 free(pData);
140 }
141 RegCloseKey(hKey);
142 *pdwNumIf = i;
143 } else {
144 result = errCode;
145 }
146 return result;
147 }
148
149
150 DWORD
151 WINAPI
152 GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG pOutBufLen)
153 {
154 DWORD result = ERROR_SUCCESS;
155 DWORD dwSize;
156 DWORD dwOutBufLen;
157 DWORD dwNumIf;
158 HKEY hKey;
159 LONG errCode;
160 int i = 0;
161
162 if ((errCode = GetNumberOfInterfaces(&dwNumIf)) != NO_ERROR) {
163 _tprintf(_T("GetInterfaceInfo() failed with code 0x%08X - Use FormatMessage to obtain the message string for the returned error\n"), errCode);
164 return errCode;
165 }
166 if (dwNumIf == 0) return ERROR_NO_DATA; // No adapter information exists for the local computer
167 if (pOutBufLen == NULL) return ERROR_INVALID_PARAMETER;
168 dwOutBufLen = sizeof(IP_INTERFACE_INFO) + dwNumIf * sizeof(IP_ADAPTER_INDEX_MAP);
169 if (*pOutBufLen < dwOutBufLen || pIfTable == NULL) {
170 *pOutBufLen = dwOutBufLen;
171 return ERROR_INSUFFICIENT_BUFFER;
172 }
173 memset(pIfTable, 0, dwOutBufLen);
174 pIfTable->NumAdapters = dwNumIf - 1;
175 errCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, KEY_READ, &hKey);
176 if (errCode == ERROR_SUCCESS) {
177 errCode = RegQueryValueExW(hKey, L"Bind", NULL, NULL, NULL, &dwSize);
178 if (errCode == ERROR_SUCCESS) {
179 wchar_t* pData = (wchar_t*)malloc(dwSize * sizeof(wchar_t));
180 errCode = RegQueryValueExW(hKey, L"Bind", NULL, NULL, (LPBYTE)pData, &dwSize);
181 if (errCode == ERROR_SUCCESS) {
182 wchar_t* pStr = pData;
183 for (i = 0; i < pIfTable->NumAdapters, *pStr != L'\0'; pStr += wcslen(pStr) + 1) {
184 if (wcsstr(pStr, L"\\Device\\NdisWanIp") == 0) {
185 wcsncpy(pIfTable->Adapter[i].Name, pStr, MAX_ADAPTER_NAME);
186 pIfTable->Adapter[i].Index = i++;
187 }
188 }
189
190 }
191 free(pData);
192 }
193 RegCloseKey(hKey);
194 } else {
195 result = errCode;
196 }
197 return result;
198 }
199
200 DWORD
201 WINAPI
202 GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
203 {
204 DWORD result = ERROR_SUCCESS;
205 DWORD dwSize;
206 HKEY hKey;
207 LONG errCode;
208
209 if (pFixedInfo == NULL || pOutBufLen == NULL) return ERROR_INVALID_PARAMETER;
210
211 if (*pOutBufLen < sizeof(FIXED_INFO)) {
212 *pOutBufLen = sizeof(FIXED_INFO);
213 return ERROR_BUFFER_OVERFLOW;
214 }
215 memset(pFixedInfo, 0, sizeof(FIXED_INFO));
216
217 errCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"), 0, KEY_READ, &hKey);
218 if (errCode == ERROR_SUCCESS) {
219 dwSize = sizeof(pFixedInfo->HostName);
220 errCode = RegQueryValueExA(hKey, "Hostname", NULL, NULL, (LPBYTE)&pFixedInfo->HostName, &dwSize);
221 dwSize = sizeof(pFixedInfo->DomainName);
222 errCode = RegQueryValueExA(hKey, "Domain", NULL, NULL, (LPBYTE)&pFixedInfo->DomainName, &dwSize);
223 if (errCode != ERROR_SUCCESS) {
224 dwSize = sizeof(pFixedInfo->DomainName);
225 errCode = RegQueryValueExA(hKey, "DhcpDomain", NULL, NULL, (LPBYTE)&pFixedInfo->DomainName, &dwSize);
226 }
227 dwSize = sizeof(pFixedInfo->EnableRouting);
228 errCode = RegQueryValueEx(hKey, _T("IPEnableRouter"), NULL, NULL, (LPBYTE)&pFixedInfo->EnableRouting, &dwSize);
229 RegCloseKey(hKey);
230 } else {
231 result = ERROR_NO_DATA; // No adapter information exists for the local computer
232 }
233
234 errCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters"), 0, KEY_READ, &hKey);
235 if (errCode == ERROR_SUCCESS) {
236 dwSize = sizeof(pFixedInfo->ScopeId);
237 errCode = RegQueryValueExA(hKey, "ScopeId", NULL, NULL, (LPBYTE)&pFixedInfo->ScopeId, &dwSize);
238 if (errCode != ERROR_SUCCESS) {
239 dwSize = sizeof(pFixedInfo->ScopeId);
240 errCode = RegQueryValueExA(hKey, "DhcpScopeId", NULL, NULL, (LPBYTE)&pFixedInfo->ScopeId, &dwSize);
241 }
242 dwSize = sizeof(pFixedInfo->NodeType);
243 errCode = RegQueryValueEx(hKey, _T("NodeType"), NULL, NULL, (LPBYTE)&pFixedInfo->NodeType, &dwSize);
244 if (errCode != ERROR_SUCCESS) {
245 dwSize = sizeof(pFixedInfo->NodeType);
246 errCode = RegQueryValueExA(hKey, "DhcpNodeType", NULL, NULL, (LPBYTE)&pFixedInfo->NodeType, &dwSize);
247 }
248 dwSize = sizeof(pFixedInfo->EnableProxy);
249 errCode = RegQueryValueEx(hKey, _T("EnableProxy"), NULL, NULL, (LPBYTE)&pFixedInfo->EnableProxy, &dwSize);
250 dwSize = sizeof(pFixedInfo->EnableDns);
251 errCode = RegQueryValueEx(hKey, _T("EnableDNS"), NULL, NULL, (LPBYTE)&pFixedInfo->EnableDns, &dwSize);
252 RegCloseKey(hKey);
253 } else {
254 result = ERROR_NO_DATA; // No adapter information exists for the local computer
255 }
256
257 return result;
258 }
259
260 DWORD
261 WINAPI
262 GetTcpStatistics(PMIB_TCPSTATS pStats)
263 {
264 DWORD result = NO_ERROR;
265
266 result = ERROR_NO_DATA;
267
268 return result;
269 }
270
271 DWORD
272 WINAPI
273 GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
274 {
275 DWORD result = NO_ERROR;
276
277 result = ERROR_NO_DATA;
278
279 return result;
280 }
281
282 DWORD
283 WINAPI
284 GetUdpStatistics(PMIB_UDPSTATS pStats)
285 {
286 DWORD result = NO_ERROR;
287
288 result = ERROR_NO_DATA;
289
290 return result;
291 }
292
293 DWORD
294 WINAPI
295 GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
296 {
297 DWORD result = NO_ERROR;
298
299 result = ERROR_NO_DATA;
300
301 return result;
302 }
303
304 DWORD
305 WINAPI
306 FlushIpNetTable(DWORD dwIfIndex)
307 {
308 DWORD result = NO_ERROR;
309
310 return result;
311 }
312
313 /* EOF */
314