source: branches/branch-1-0/src/helpers/lan.c@ 297

Last change on this file since 297 was 229, checked in by umoeller, 23 years ago

Sources as of 1.0.0.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1
2/*
3 *@@sourcefile lan.c:
4 * LAN helpers.
5 *
6 * Usage: All OS/2 programs.
7 *
8 * Function prefixes (new with V0.81):
9 * -- nls* LAN helpers
10 *
11 * This file is new with 0.9.16.
12 *
13 * Note: Version numbering in this file relates to XWorkplace version
14 * numbering.
15 *
16 *@@header "helpers\nls.h"
17 *@@added V0.9.16 (2001-10-19) [umoeller]
18 */
19
20/*
21 * Copyright (C) 2001 Ulrich M”ller.
22 * This file is part of the "XWorkplace helpers" source package.
23 * This is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published
25 * by the Free Software Foundation, in version 2 as it comes in the
26 * "COPYING" file of the XWorkplace main distribution.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 */
32
33#define OS2EMX_PLAIN_CHAR
34 // this is needed for "os2emx.h"; if this is defined,
35 // emx will define PSZ as _signed_ char, otherwise
36 // as unsigned char
37
38#define INCL_DOS
39#include <os2.h>
40
41// #define PURE_32
42// #include <neterr.h>
43// #include <netcons.h>
44// #include <server.h>
45
46#include <stdlib.h>
47#include <stdio.h>
48#include <string.h>
49
50#include "setup.h" // code generation and debugging options
51
52#include "helpers\dosh.h"
53#include "helpers\lan.h"
54#include "helpers\standards.h"
55
56#pragma hdrstop
57
58/*
59 *@@category: Helpers\Network helpers
60 * See lan.c.
61 */
62
63/* ******************************************************************
64 *
65 * Prototypes
66 *
67 ********************************************************************/
68
69#define API32_FUNCTION APIRET APIENTRY
70
71typedef API32_FUNCTION NET32WKSTAGETINFO(PCSZ pszServer,
72 unsigned long ulLevel,
73 PBYTE pbBuffer,
74 unsigned long ulBuffer,
75 unsigned long *pulTotalAvail);
76
77typedef API32_FUNCTION NET32SERVERENUM2(PCSZ pszServer,
78 unsigned long ulLevel,
79 PBYTE pbBuffer,
80 unsigned long cbBuffer,
81 unsigned long *pcEntriesRead,
82 unsigned long *pcTotalAvail,
83 unsigned long flServerType,
84 PBYTE pszDomain);
85
86typedef API32_FUNCTION NET32SERVICESTATUS(PCSZ pbBuffer,
87 unsigned long ulBuffer);
88
89typedef API32_FUNCTION NET32SERVICEGETINFO(PCSZ pszServer,
90 PCSZ pszService,
91 unsigned long ulLevel,
92 PBYTE pbBuffer,
93 unsigned long ulBuffer,
94 unsigned long *pulTotalAvail);
95
96typedef API32_FUNCTION NET32SERVICECONTROL(PCSZ pszServer,
97 PCSZ pszService,
98 unsigned short usOpcode,
99 unsigned short usArg,
100 PBYTE pbBuffer,
101 unsigned long ulBuffer);
102
103typedef API32_FUNCTION NET32SERVICEINSTALL(PCSZ pszServer,
104 PCSZ pszService,
105 PCSZ pszCmdArgs,
106 PBYTE pbBuffer,
107 unsigned long ulBuffer);
108
109/* ******************************************************************
110 *
111 * Globals
112 *
113 ********************************************************************/
114
115HMODULE hmodLan = NULLHANDLE;
116
117NET32WKSTAGETINFO *pNet32WkstaGetInfo = NULL;
118NET32SERVERENUM2 *pNet32ServerEnum2 = NULL;
119NET32SERVICESTATUS *pNet32ServiceStatus = NULL;
120NET32SERVICEGETINFO *pNet32ServiceGetInfo = NULL;
121NET32SERVICECONTROL *pNet32ServiceControl = NULL;
122NET32SERVICEINSTALL *pNet32ServiceInstall = NULL;
123
124RESOLVEFUNCTION NetResolves[] =
125 {
126 "Net32WkstaGetInfo", (PFN*)&pNet32WkstaGetInfo,
127 "Net32ServerEnum2", (PFN*)&pNet32ServerEnum2,
128 "Net32ServiceStatus", (PFN*)&pNet32ServiceStatus,
129 "Net32ServiceGetInfo", (PFN*)&pNet32ServiceGetInfo,
130 "Net32ServiceControl", (PFN*)&pNet32ServiceControl,
131 "Net32ServiceInstall", (PFN*)&pNet32ServiceInstall,
132 };
133
134STATIC ULONG G_ulNetsResolved = -1; // -1 == not init'd
135 // 0 == success
136 // APIRET == failure
137
138/*
139 *@@ lanInit:
140 * initializes the LAN server interface.
141 *
142 * Returns:
143 *
144 * -- NO_ERROR: functions resolved successfully,
145 * engine is ready.
146 *
147 * or the error codes from doshResolveImports.
148 */
149
150APIRET lanInit(VOID)
151{
152 if (G_ulNetsResolved == -1)
153 {
154 G_ulNetsResolved = doshResolveImports("NETAPI32", // \MUGLIB\DLL
155 &hmodLan,
156 NetResolves,
157 ARRAYITEMCOUNT(NetResolves));
158 }
159
160 return G_ulNetsResolved;
161}
162
163/*
164 *@@ lanQueryServers:
165 * returns an array of SERVER structures describing
166 * the servers which are available from this computer.
167 *
168 * With PEER, this should return the peers, assuming
169 * that remote IBMLAN.INI's do not contain "srvhidden = yes".
170 *
171 * If NO_ERROR is returned, the caller should free()
172 * the returned array
173 */
174
175APIRET lanQueryServers(PSERVER *paServers, // out: array of SERVER structs
176 ULONG *pcServers) // out: array item count (NOT array size)
177{
178 APIRET arc;
179
180 if (!(arc = lanInit()))
181 {
182 ULONG ulEntriesRead = 0,
183 cTotalAvail = 0;
184 PSERVER pBuf;
185 ULONG cb = 4096; // set this fixed, can't get it to work otherwise
186 if (pBuf = (PSERVER)doshMalloc(cb,
187 &arc))
188 {
189 if (!(arc = pNet32ServerEnum2(NULL,
190 1, // ulLevel
191 (PBYTE)pBuf, // pbBuffer
192 cb, // cbBuffer,
193 &ulEntriesRead, // *pcEntriesRead,
194 &cTotalAvail, // *pcTotalAvail,
195 SV_TYPE_ALL, // all servers
196 NULL))) // pszDomain == all domains
197 {
198 *pcServers = ulEntriesRead;
199 *paServers = pBuf;
200 }
201 else
202 free(pBuf);
203 }
204 }
205
206 printf(__FUNCTION__ ": arc %d\n", arc);
207
208 return arc;
209}
210
211/*
212 *@@ lanServiceGetInfo:
213 * queries the given service.
214 *
215 *@@added V1.0.0 (2002-09-24) [umoeller]
216 */
217
218APIRET lanServiceGetInfo(PCSZ pcszServiceName,
219 PSERVICEBUF2 pBuf)
220{
221 APIRET arc;
222
223 if (!(arc = lanInit()))
224 {
225 ULONG ulBytesAvail = 0;
226 arc = pNet32ServiceGetInfo(NULL,
227 pcszServiceName,
228 2, // level
229 (PBYTE)pBuf,
230 sizeof(SERVICEBUF2),
231 &ulBytesAvail);
232
233 }
234
235 return arc;
236}
237/*
238 *@@ lanServiceInstall:
239 * starts the given service. The service name
240 * must be fully qualified so you cannot
241 * abbreviate "requester" with "req", for
242 * example (as valid with the net command).
243 *
244 * Returns, among others:
245 *
246 * -- NO_ERROR
247 *
248 * -- NERR_ServiceInstalled (2182): the service
249 * has already been started.
250 *
251 * -- NERR_BadServiceName (2185): invalid service
252 * name.
253 *
254 *@@added V1.0.0 (2002-09-24) [umoeller]
255 */
256
257APIRET lanServiceInstall(PCSZ pcszServiceName,
258 PSERVICEBUF2 pBuf2) // out: service data
259{
260 APIRET arc;
261
262 if (!(arc = lanInit()))
263 {
264 SERVICEBUF2 buf2;
265
266 if (!(arc = pNet32ServiceInstall(NULL,
267 pcszServiceName,
268 NULL,
269 (PBYTE)pBuf2,
270 sizeof(SERVICEBUF2))))
271 ;
272 }
273
274 return arc;
275}
276
277/*
278 *@@ lanServiceControl:
279 * queries, pauses, resumes, or stops the given service.
280 *
281 * opcode must be one of:
282 *
283 * -- SERVICE_CTRL_INTERROGATE (0): interrogate service status.
284 *
285 * -- SERVICE_CTRL_PAUSE (1): pause service.
286 *
287 * -- SERVICE_CTRL_CONTINUE (2): continue service.
288 *
289 * -- SERVICE_CTRL_UNINSTALL (3): stop service.
290 *
291 *@@added V1.0.0 (2002-09-24) [umoeller]
292 */
293
294APIRET lanServiceControl(PCSZ pcszServiceName,
295 ULONG opcode,
296 PSERVICEBUF2 pBuf2) // out: service data
297{
298 APIRET arc;
299
300 if (!(arc = lanInit()))
301 {
302 if (!(arc = pNet32ServiceControl(NULL,
303 pcszServiceName,
304 opcode,
305 0,
306 (PBYTE)pBuf2,
307 sizeof(SERVICEBUF2))))
308 ;
309
310 }
311
312 return arc;
313}
314
315#ifdef __LAN_TEST__
316
317int main(void)
318{
319 ULONG ul;
320
321 PSERVER paServers;
322 ULONG cServers;
323 lanQueryServers(&paServers, &cServers);
324
325 for (ul = 0;
326 ul < cServers;
327 ul++)
328 {
329 printf("Server %d: \\\\%s (%s)\n",
330 ul,
331 paServers[ul].achServerName,
332 paServers[ul].pszComment);
333 }
334
335 return 0;
336}
337
338#endif
339
Note: See TracBrowser for help on using the repository browser.