source: trunk/src/iphlpapi/iphlpapi.cpp@ 6994

Last change on this file since 6994 was 6994, checked in by phaller, 24 years ago

.

File size: 6.6 KB
Line 
1/* $Id: iphlpapi.cpp,v 1.3 2001-10-10 17:37:44 phaller Exp $ */
2/*
3 * IPHLPAPI library
4 *
5 */
6
7
8/****************************************************************************
9 * includes
10 ****************************************************************************/
11
12#include <odin.h>
13#include <odinwrap.h>
14#include <os2sel.h>
15
16#include <os2win.h>
17#include <odinwrap.h>
18#include <winversion.h>
19
20#include <string.h>
21
22#include "iphlpapi.h"
23
24ODINDEBUGCHANNEL(IPHLPAPI-IPHLPAPI)
25
26
27/****************************************************************************
28 * module global variables
29 ****************************************************************************/
30
31static PIP_ADAPTER_INFO pipAdapters = NULL;
32
33
34//******************************************************************************
35//******************************************************************************
36static 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
74static 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
84static 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}
129
130
131//******************************************************************************
132//******************************************************************************
133ODINFUNCTION2(DWORD, GetAdaptersInfo,
134 PIP_ADAPTER_INFO, pAdapterInfo,
135 PULONG, pOutBufLen)
136{
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;
145
146 if (NULL == pipAdapters)
147 {
148 // gather the information and save it
149 i_initializeAdapterInformation();
150
151 // determine number of IP adapters (interfaces) in the system
152
153 // os2_ioctl() SIOSTATIF42
154 }
155
156 if (NULL == pipAdapters)
157 return ERROR_NO_DATA;
158
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 }
202
203 return ERROR_SUCCESS;
204}
205
206
207//******************************************************************************
208//******************************************************************************
209ODINFUNCTION2(DWORD, GetNetworkParams,
210 PFIXED_INFO, pFixedInfo,
211 PULONG, pOutBufLen)
212{
213 dprintf(("GetNetworkParams not implemented"));
214 return ERROR_NOT_SUPPORTED; //NT returns this
215}
216//******************************************************************************
217//******************************************************************************
218
219
220DWORD AddIPAddress(IPAddr Address, // IP address to add
221 IPMask IpMask, // subnet mask for IP address
222 DWORD IfIndex, // index of adapter
223 PULONG NTEContext, // Net Table Entry context
224 PULONG NTEInstance // Net Table Entry Instance
225 );
226// SIOCAIFADDR
227
228DWORD DeleteIPAddress(
229 ULONG NTEContext // net table entry context
230 );
231// SIOCDIFADDR
Note: See TracBrowser for help on using the repository browser.