2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Winsock 2 IP Helper API DLL
6 * PROGRAMMERS: Robert Dickenson (robd@reactos.org)
8 * RDD August 18, 2002 Created
24 #define EXPORT STDCALL
26 #define EXPORT CALLBACK
31 /* See debug.h for debug/trace constants */
32 DWORD DebugTraceLevel
= MAX_TRACE
;
36 /* To make the linker happy */
37 //VOID STDCALL KeBugCheck (ULONG BugCheckCode) {}
42 DllMain(HANDLE hInstDll
,
46 //WSH_DbgPrint(MIN_TRACE, ("DllMain of iphlpapi.dll\n"));
49 case DLL_PROCESS_ATTACH
:
50 /* Don't need thread attach notifications
51 so disable them to improve performance */
52 DisableThreadLibraryCalls(hInstDll
);
55 case DLL_THREAD_ATTACH
:
58 case DLL_THREAD_DETACH
:
61 case DLL_PROCESS_DETACH
:
70 AddIPAddress(IPAddr Address
, IPMask IpMask
, DWORD IfIndex
, PULONG NTEContext
, PULONG NTEInstance
)
79 SetIpNetEntry(PMIB_IPNETROW pArpEntry
)
87 CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute
)
98 GetAdapterIndex(LPWSTR AdapterName
, PULONG IfIndex
)
105 GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
)
113 ////////////////////////////////////////////////////////////////////////////////
117 GetNumberOfInterfaces(OUT PDWORD pdwNumIf
)
119 DWORD result
= NO_ERROR
;
124 if (pdwNumIf
== NULL
) return ERROR_INVALID_PARAMETER
;
126 errCode
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, KEY_READ
, &hKey
);
127 if (errCode
== ERROR_SUCCESS
) {
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
152 GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable
, PULONG pOutBufLen
)
154 DWORD result
= ERROR_SUCCESS
;
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
);
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
;
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
++;
202 GetNetworkParams(PFIXED_INFO pFixedInfo
, PULONG pOutBufLen
)
204 DWORD result
= ERROR_SUCCESS
;
209 if (pFixedInfo
== NULL
|| pOutBufLen
== NULL
) return ERROR_INVALID_PARAMETER
;
211 if (*pOutBufLen
< sizeof(FIXED_INFO
)) {
212 *pOutBufLen
= sizeof(FIXED_INFO
);
213 return ERROR_BUFFER_OVERFLOW
;
215 memset(pFixedInfo
, 0, sizeof(FIXED_INFO
));
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
);
227 dwSize
= sizeof(pFixedInfo
->EnableRouting
);
228 errCode
= RegQueryValueEx(hKey
, _T("IPEnableRouter"), NULL
, NULL
, (LPBYTE
)&pFixedInfo
->EnableRouting
, &dwSize
);
231 result
= ERROR_NO_DATA
; // No adapter information exists for the local computer
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
);
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
);
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
);
254 result
= ERROR_NO_DATA
; // No adapter information exists for the local computer
262 GetTcpStatistics(PMIB_TCPSTATS pStats
)
264 DWORD result
= NO_ERROR
;
266 result
= ERROR_NO_DATA
;
273 GetTcpTable(PMIB_TCPTABLE pTcpTable
, PDWORD pdwSize
, BOOL bOrder
)
275 DWORD result
= NO_ERROR
;
277 result
= ERROR_NO_DATA
;
284 GetUdpStatistics(PMIB_UDPSTATS pStats
)
286 DWORD result
= NO_ERROR
;
288 result
= ERROR_NO_DATA
;
295 GetUdpTable(PMIB_UDPTABLE pUdpTable
, PDWORD pdwSize
, BOOL bOrder
)
297 DWORD result
= NO_ERROR
;
299 result
= ERROR_NO_DATA
;
306 FlushIpNetTable(DWORD dwIfIndex
)
308 DWORD result
= NO_ERROR
;