-
Notifications
You must be signed in to change notification settings - Fork 4
/
misc.c
executable file
·401 lines (363 loc) · 8.04 KB
/
misc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*[[ CMS REPLACEMENT HISTORY, Element MISC.C]]*/
/*[[ *4 16-FEB-2002 12:04:08 MADISON ""]]*/
/*[[ *3 20-JAN-2002 10:01:08 MADISON "Updates for V2.3C"]]*/
/*[[ *2 19-JAN-2001 08:35:52 MADISON "Move version-dependent source files to ETCDIR"]]*/
/*[[ *1 12-MAR-1998 16:41:00 MADISON "Initial CMS population"]]*/
/*[[ CMS REPLACEMENT HISTORY, Element MISC.C]]*/
/*
**++
** FACILITY: NETLIB
**
** ABSTRACT: Miscellaneous routines.
**
** MODULE DESCRIPTION:
**
** tbs
**
** AUTHOR: M. Madison
** COPYRIGHT © 1994, 2002 MADGOAT SOFTWARE. ALL RIGHTS RESERVED.
**
** CREATION DATE: 22-OCT-1994
**
** MODIFICATION HISTORY:
**
** 22-OCT-1994 V1.0 Madison Initial coding.
** 27-NOV-1997 V1.1 Madison Added version info.
** 10-JAN-2002 V1.2 Madison Don't allow extra dot after dotted-quad.
** 04-FEB-2002 V1.2-1 Madison Last change was not correctly checking
** final length.
**--
*/
#include "netlib.h"
#include "etc_dir:netlib_version.h"
#ifdef __DECC
#pragma extern_model save
#pragma extern_model common_block shr
#endif
char $$$Copyright[] = "Copyright © 1992,1994,1996-2002 MadGoat Software. All Rights Reserved.";
#ifdef __DECC
#pragma extern_model restore
#endif
/*
** Forward declarations
*/
unsigned int netlib_strtoaddr(struct dsc$descriptor *dsc, struct INADDRDEF *a);
unsigned int netlib_addrtostr(struct INADDRDEF *, struct dsc$descriptor *,
unsigned short *);
unsigned int netlib___find_symbol(char *imgnam, char *symnam, void *symptr);
static unsigned int find_image_symbol(struct dsc$descriptor *imgdsc,
struct dsc$descriptor *symdsc, void *symptr);
unsigned int netlib_hton_long(unsigned int *);
unsigned int netlib_ntoh_long(unsigned int *);
unsigned short netlib_hton_word(unsigned short *);
unsigned short netlib_ntoh_short(unsigned short *);
unsigned int netlib_version(struct dsc$descriptor *ver, unsigned short *retlen);
/*
**++
** ROUTINE: netlib_strtoaddr
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned int netlib_strtoaddr (struct dsc$descriptor *dsc, struct INADDRDEF *a) {
unsigned short len;
char *cp, *anchor;
unsigned int status, parts[4], val;
int i;
status = lib$analyze_sdesc(dsc, &len, &cp);
if (!OK(status)) return status;
for (i = 0; len > 0 && i < 4; i++) {
val = 0;
while (*cp != '.' && len > 0) {
if (!isdigit(*cp)) return SS$_IVADDR;
val = val * 10 + (*cp - '0');
cp++; len--;
}
parts[i] = val;
if (len > 0) {
cp++; len--;
}
}
switch (i) {
case 0: return SS$_IVADDR;
case 1: val = parts[0];
break;
case 2: val = (parts[0] << 24) | (parts[1] & 0xffffff);
break;
case 3: val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
(parts[2] & 0xffff);
break;
case 4: if (len > 0)
return SS$_IVADDR;
val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) |
((parts[2] & 0xff) << 8) | (parts[3] & 0xff);
break;
}
a->inaddr_l_addr = netlib_long_swap(val);
return SS$_NORMAL;
} /* netlib_strtoaddr */
/*
**++
** ROUTINE: netlib_addrtostr
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned int netlib_addrtostr (struct INADDRDEF *addr,
struct dsc$descriptor *dsc, unsigned short *len) {
int argc;
static $DESCRIPTOR(faodsc, "!UB.!UB.!UB.!UB");
SETARGCOUNT(argc);
return lib$sys_fao(&faodsc, (argc > 2) ? len : 0, dsc,
(addr->inaddr_l_addr) & 0xff,
(addr->inaddr_l_addr >> 8) & 0xff,
(addr->inaddr_l_addr >> 16) & 0xff,
(addr->inaddr_l_addr >> 24) & 0xff);
} /* netlib_addrtostr */
/*
**++
** ROUTINE: netlib___find_symbol
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned int netlib___find_symbol (char *imgnam, char *symnam, void *symptr) {
struct dsc$descriptor imgdsc, symdsc;
lib$establish(lib$sig_to_ret);
INIT_SDESC(imgdsc, strlen(imgnam), imgnam);
INIT_SDESC(symdsc, strlen(symnam), symnam);
return find_image_symbol(&imgdsc, &symdsc, symptr);
} /* netlib___find_symbol */
/*
**++
** ROUTINE: find_image_symbol
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
static unsigned int find_image_symbol (struct dsc$descriptor *imgdsc,
struct dsc$descriptor *symdsc, void *symptr) {
return lib$find_image_symbol(imgdsc, symdsc, symptr);
} /* find_image_symbol */
/*
**++
** ROUTINE: netlib_hton_long
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned int netlib_hton_long (unsigned int *value) {
return netlib_long_swap(*value);
} /* netlib_hton_long */
/*
**++
** ROUTINE: netlib_ntoh_long
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned int netlib_ntoh_long (unsigned int *value) {
return netlib_long_swap(*value);
} /* netlib_ntoh_long */
/*
**++
** ROUTINE: netlib_hton_word
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, wordword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned short netlib_hton_word (unsigned short *value) {
return netlib_word_swap(*value);
} /* netlib_hton_word */
/*
**++
** ROUTINE: netlib_ntoh_word
**
** FUNCTIONAL DESCRIPTION:
**
** tbs
**
** RETURNS: cond_value, wordword (unsigned), write only, by value
**
** PROTOTYPE:
**
** tbs
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES:
**
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned short netlib_ntoh_word (unsigned short *value) {
return netlib_word_swap(*value);
} /* netlib_ntoh_word */
/*
**++
** ROUTINE: netlib_version
**
** FUNCTIONAL DESCRIPTION:
**
** Returns the NETLIB version string.
**
** RETURNS: cond_value, condition value, longword (unsigned), write only, by value
**
** PROTOTYPE:
**
** NETLIB_VERSION ver [,retlen]
**
** ver: char_string, character string, write only, by descriptor
** retlen: word_unsigned, word (unsigned), write only, by reference
**
** IMPLICIT INPUTS: None.
**
** IMPLICIT OUTPUTS: None.
**
** COMPLETION CODES: None.
**
** SIDE EFFECTS: None.
**
**--
*/
unsigned int netlib_version (struct dsc$descriptor *ver, unsigned short *retlen) {
int argc;
unsigned int status;
static char version_string[] = NETLIB_T_VERSION;
static $DESCRIPTOR(faodsc, "!AD");
SETARGCOUNT(argc);
if (argc < 1) return SS$_INSFARG;
if (ver == 0) return SS$_BADPARAM;
return lib$sys_fao(&faodsc, (argc > 1 ? retlen : 0), ver,
sizeof(version_string)-1, version_string);
} /* netlib_version */