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

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

.

File size: 6.6 KB
Line 
1/* $Id: iphlpapi.cpp,v 1.4 2001-10-10 22:55:21 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 <winversion.h>
18
19#include <string.h>
20
21#include "iphlpapi.h"
22
23ODINDEBUGCHANNEL(IPHLPAPI-IPHLPAPI)
24
25
26/****************************************************************************
27 * module global variables
28 ****************************************************************************/
29
30static PIP_ADAPTER_INFO pipAdapters = NULL;
31
32
33//******************************************************************************
34//******************************************************************************
35static void i_initializeAdapterInformation(void)
36{
37 // @@@PH
38 // yet a fake to test some app
39 pipAdapters = (PIP_ADAPTER_INFO)malloc (sizeof (IP_ADAPTER_INFO) );
40
41 memset(pipAdapters, 0, sizeof( IP_ADAPTER_INFO ));
42 pipAdapters->Next = NULL;
43 pipAdapters->ComboIndex = 1;
44 strcpy(pipAdapters->AdapterName, "ODIN IPHLPAPI Test Adapter");
45 strcpy(pipAdapters->Description, "ODIN IPHLPAPI Test Adapter (faked information)");
46 pipAdapters->AddressLength = 4;
47 pipAdapters->Address[0] = 127;
48 pipAdapters->Address[1] = 0;
49 pipAdapters->Address[2] = 0;
50 pipAdapters->Address[3] = 1;
51 pipAdapters->Index = 1;
52 pipAdapters->Type = 1;
53 pipAdapters->DhcpEnabled = 0;
54
55 static IP_ADDR_STRING iasLocalhost;
56 iasLocalhost.Next = NULL;
57 strcpy((char*)&iasLocalhost.IpAddress,"127.0.0.1");
58 strcpy((char*)&iasLocalhost.IpMask, "255.0.0.0");
59 iasLocalhost.Context = 0;
60
61 memcpy((char*)&pipAdapters->IpAddressList, (char*)&iasLocalhost, sizeof(iasLocalhost));
62 pipAdapters->CurrentIpAddress = &pipAdapters->IpAddressList;
63 memcpy((char*)&pipAdapters->GatewayList, (char*)&iasLocalhost, sizeof(iasLocalhost));
64 memset((char*)&pipAdapters->DhcpServer, 0, sizeof( IP_ADDR_STRING ) );
65 pipAdapters->HaveWins = 0;
66 memset((char*)&pipAdapters->PrimaryWinsServer, 0, sizeof( IP_ADDR_STRING ) );
67 memset((char*)&pipAdapters->SecondaryWinsServer, 0, sizeof( IP_ADDR_STRING ) );
68 pipAdapters->LeaseObtained = 0;
69 pipAdapters->LeaseExpires = 0;
70}
71
72// copy over the whole list and advance the target pointer
73static void i_copyIP_ADDRESS_STRING(PBYTE *ppTarget, PIP_ADDR_STRING pias)
74{
75 while (pias)
76 {
77 memcpy(*ppTarget, pias, sizeof( IP_ADDR_STRING ) );
78 *ppTarget += sizeof ( IP_ADDR_STRING );
79 pias = pias->Next;
80 }
81}
82
83static DWORD i_sizeOfIP_ADAPTER_INFO(PIP_ADAPTER_INFO piai)
84{
85 PIP_ADDR_STRING pias;
86
87 // check for sufficient space
88 DWORD dwRequired = sizeof( IP_ADAPTER_INFO );
89
90 // follow the IP_ADDR_STRING lists
91 pias = &piai->IpAddressList;
92 while( pias )
93 {
94 dwRequired += sizeof( IP_ADDR_STRING );
95 pias = pias->Next;
96 }
97
98 pias = &piai->GatewayList;
99 while( pias )
100 {
101 dwRequired += sizeof( IP_ADDR_STRING );
102 pias = pias->Next;
103 }
104
105 pias = &piai->DhcpServer;
106 while( pias )
107 {
108 dwRequired += sizeof( IP_ADDR_STRING );
109 pias = pias->Next;
110 }
111
112 pias = &piai->PrimaryWinsServer;
113 while( pias )
114 {
115 dwRequired += sizeof( IP_ADDR_STRING );
116 pias = pias->Next;
117 }
118
119 pias = &piai->SecondaryWinsServer;
120 while( pias )
121 {
122 dwRequired += sizeof( IP_ADDR_STRING );
123 pias = pias->Next;
124 }
125
126 return dwRequired;
127}
128
129
130//******************************************************************************
131//******************************************************************************
132ODINFUNCTION2(DWORD, GetAdaptersInfo,
133 PIP_ADAPTER_INFO, pAdapterInfo,
134 PULONG, pOutBufLen)
135{
136 dprintf(("GetAdaptersInfo incorrectly implemented"));
137
138 if (NULL == pOutBufLen)
139 return ERROR_INVALID_PARAMETER;
140
141 // verify first block of memory to write to
142 if (IsBadWritePtr(pAdapterInfo, 4))
143 return ERROR_INVALID_PARAMETER;
144
145 if (NULL == pipAdapters)
146 {
147 // gather the information and save it
148 i_initializeAdapterInformation();
149
150 // determine number of IP adapters (interfaces) in the system
151
152 // os2_ioctl() SIOSTATIF42
153 }
154
155 if (NULL == pipAdapters)
156 return ERROR_NO_DATA;
157
158 // OK, just copy over the information as far as possible
159 LONG lSpaceLeft = *pOutBufLen;
160 PBYTE pTarget = (PBYTE)pAdapterInfo;
161 PIP_ADAPTER_INFO pip;
162
163 // calculate overall required buffer size
164 DWORD dwRequiredBuffer = 0;
165
166 for( pip = pipAdapters ; pip ; pip = pip->Next )
167 {
168 // check for sufficient space
169 dwRequiredBuffer += i_sizeOfIP_ADAPTER_INFO(pip);
170 }
171
172 for( pip = pipAdapters ; pip ; pip = pip->Next )
173 {
174 // check for sufficient space
175 DWORD dwRequired = i_sizeOfIP_ADAPTER_INFO(pip);
176
177 if (lSpaceLeft - dwRequired > 0)
178 {
179 lSpaceLeft -= dwRequired;
180
181 // copy over the whole structure hierarchy
182 memcpy(pTarget, pip, sizeof( IP_ADAPTER_INFO ));
183 pTarget += sizeof( IP_ADAPTER_INFO );
184
185 // @@@PH shall point to somewhere within the current buffer
186 pip->CurrentIpAddress = (PIP_ADDR_STRING)pTarget;
187
188 i_copyIP_ADDRESS_STRING(&pTarget, &pip->IpAddressList);
189 i_copyIP_ADDRESS_STRING(&pTarget, &pip->GatewayList);
190 i_copyIP_ADDRESS_STRING(&pTarget, &pip->DhcpServer);
191 i_copyIP_ADDRESS_STRING(&pTarget, &pip->PrimaryWinsServer);
192 i_copyIP_ADDRESS_STRING(&pTarget, &pip->SecondaryWinsServer);
193 }
194 else
195 {
196 // return overall size of required buffer
197 *pOutBufLen = dwRequiredBuffer;
198 return ERROR_BUFFER_OVERFLOW;
199 }
200 }
201
202 return ERROR_SUCCESS;
203}
204
205
206//******************************************************************************
207//******************************************************************************
208ODINFUNCTION2(DWORD, GetNetworkParams,
209 PFIXED_INFO, pFixedInfo,
210 PULONG, pOutBufLen)
211{
212 dprintf(("GetNetworkParams not implemented"));
213 return ERROR_NOT_SUPPORTED; //NT returns this
214}
215//******************************************************************************
216//******************************************************************************
217
218
219DWORD AddIPAddress(IPAddr Address, // IP address to add
220 IPMask IpMask, // subnet mask for IP address
221 DWORD IfIndex, // index of adapter
222 PULONG NTEContext, // Net Table Entry context
223 PULONG NTEInstance // Net Table Entry Instance
224 );
225// SIOCAIFADDR
226
227DWORD DeleteIPAddress(
228 ULONG NTEContext // net table entry context
229 );
230// SIOCDIFADDR
Note: See TracBrowser for help on using the repository browser.