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
|
/*
* SCCS: @(#)tcm_in.c 1.13 (98/09/01)
*
* UniSoft Ltd., London, England
*
* (C) Copyright 1992 X/Open Company Limited
*
* All rights reserved. No part of this source code may be reproduced,
* stored in a retrieval system, or transmitted, in any form or by any
* means, electronic, mechanical, photocopying, recording or otherwise,
* except as stated in the end-user licence agreement, without the prior
* permission of the copyright owners.
*
* X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
* the UK and other countries.
*/
#ifndef lint
static char sccsid[] = "@(#)tcm_in.c 1.13 (98/09/01) TET3 release 3.3";
#endif
/************************************************************************
SCCS: @(#)tcm_in.c 1.13 98/09/01 TETware release 3.3
NAME: tcm_in.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: April 1992
DESCRIPTION:
client-specific functions for tcm INET version
MODIFICATIONS:
Denis McConalogue, UniSoft Limited, August 1993
Make sure the loopback address is not put in the tsinfo message
when the message destination is a different machine.
Andrew Dingwall, UniSoft Ltd., December 1993
added ptm_mtype assignment
Geoff Clare, UniSoft Ltd., Oct 1996
restructured tcm source to avoid "ld -r"
Andrew Dingwall, UniSoft Ltd., March 1997
remove #ifndef __hpux from #include <arpa/inet.h>
since current HP-UX implementations now have this file
Andrew Dingwall, UniSoft Ltd., July 1998
Added support for shared API libraries.
Changes for conformance with UNIX98.
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
# include <netinet/in.h>
# include <sys/uio.h>
# include <sys/socket.h>
# include <arpa/inet.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "ptab.h"
#include "tptab_in.h"
#include "tsinfo_in.h"
#include "error.h"
#include "globals.h"
#include "server.h"
#include "tcmfuncs.h"
#include "dtetlib.h"
#include "inetlib_in.h"
#ifndef NOTRACE
#include "ltoa.h"
#endif
#ifdef NEEDsrcFile
static char srcFile[] = __FILE__; /* file name for error reporting */
#endif
/* static function declarations */
static void storetsinfo PROTOLIST((char *, struct ptab **, int));
/*
** tet_ts_tcminit() - tcm transport-specific environment argument
** processing
*/
void tet_ts_tcminit()
{
register char **ap;
register char *envstring, *p;
char **args;
register int nargs;
static char envname[] = "TET_TSARGS";
/* get the dtet ts args out of the environment and count them */
if ((envstring = getenv(envname)) == (char *) 0 || !*envstring)
fatal(0, envname, "null or not set");
nargs = 1;
for (p = envstring; *p; p++)
if (isspace(*p))
nargs++;
/* allocate some space for argument pointers */
errno = 0;
if ((args = (char **) malloc(nargs * sizeof *args)) == (char **) 0)
fatal(errno, "can't get memory for arg list", (char *) 0);
TRACE2(tet_Tbuf, 6, "allocate ts env args = %s", tet_i2x(args));
/* split the arg string into fields */
nargs = tet_getargs(envstring, args, nargs);
/* process each argument in turn */
for (ap = args; nargs > 0; ap++, nargs--) {
if (*(p = *ap) != '-')
continue;
switch (*++p) {
case 'x':
storetsinfo(*ap, &tet_xdptab, PT_XRESD);
break;
case 'y':
storetsinfo(*ap, &tet_sdptab, PT_SYNCD);
break;
default:
fatal(0, "bad ts env argument", *ap);
/* NOTREACHED */
}
}
TRACE2(tet_Tbuf, 6, "free ts env args = %s", tet_i2x(args));
free((char *) args);
}
/*
** storetsinfo() - store ts info for server process
**
** the ts info is stored indirectly through *paddr
*/
static void storetsinfo(arg, paddr, ptype)
char *arg;
struct ptab **paddr;
int ptype;
{
register struct ptab *pp;
register struct tptab *tp;
register char *addr, *port;
/* make addr point to the INET address string
and port to the port string */
addr = arg + 2;
for (port = addr; *port; port++)
if (*port == ',') {
*port++ = '\0';
break;
}
if (!*addr || !*port)
fatal(0, "bad ts env arg format:", arg);
/* get a ptab structure and fill it in */
if ((pp = tet_ptalloc()) == (struct ptab *) 0)
exit(1);
pp->ptr_sysid = 0;
pp->ptr_ptype = ptype;
pp->pt_flags = PF_SERVER;
tp = (struct tptab *) pp->pt_tdata;
/* fill in the INET address structure */
tp->tp_sin.sin_family = AF_INET;
if ((tp->tp_sin.sin_addr.s_addr = inet_addr(addr)) == -1) {
*(port - 1) = ',';
fatal(0, "bad format INET address:", arg);
}
if ((tp->tp_sin.sin_port = htons((unsigned short) atoi(port))) == 0) {
*(port - 1) = ',';
fatal(0, "bad port number:", arg);
}
*paddr = pp;
}
/*
** tet_tcm_tsconnect() - server-specific connect processing
**
** return 0 if successful or -1 on error
*/
int tet_tcm_tsconnect(pp)
struct ptab *pp;
{
switch (pp->ptr_ptype) {
case PT_SYNCD:
if (tet_sdptab)
return(0);
break;
case PT_XRESD:
if (tet_xdptab)
return(0);
break;
case PT_STCC:
return(tet_gettccdaddr(pp));
}
error(0, "don't know how to connect to", tet_ptptype(pp->ptr_ptype));
return(-1);
}
/*
** tet_tcm_tsinfo() - construct a tsinfo message relating to a server
** process
**
** return 0 if successful or -1 on error
*/
int tet_tcm_tsinfo(pp, ptype)
struct ptab *pp;
register int ptype;
{
register struct tptab *tp;
register struct tsinfo *mp;
struct in_addr *ap;
char hostname[SNAMELEN];
if ((mp = (struct tsinfo *) tet_ti_msgbuf(pp, sizeof *mp)) == (struct tsinfo *) 0)
return(-1);
/* make tp point to the tptab for the server -
tet_sdptab and tet_xdptab were set up if the corresponding
arguments were in the TET_TSARGS environment variable */
tp = (struct tptab *) 0;
switch (ptype) {
case PT_SYNCD:
if (tet_sdptab)
tp = (struct tptab *) tet_sdptab->pt_tdata;
break;
case PT_XRESD:
if (tet_xdptab)
tp = (struct tptab *) tet_xdptab->pt_tdata;
break;
}
if (!tp) {
error(0, "no tsinfo for", tet_ptptype(ptype));
return(-1);
}
/* all ok so copy over the data and return */
mp->ts_ptype = ptype;
mp->ts_port = ntohs(tp->tp_sin.sin_port);
/*
** on system 0 we talk to syncd and xresd using the loopback address,
** so that is what is stored in the tptab structure;
** if the message destination is also localhost, simply copy the
** stored (localhost) address -
** otherwise, the destination is on another machine so find our
** (external) Internet address and use that
*/
if (
tet_mysysid == 0 &&
((struct tptab *) pp->pt_tdata)->tp_sin.sin_addr.s_addr !=
tp->tp_sin.sin_addr.s_addr
) {
if (gethostname(hostname, sizeof hostname) < 0) {
error(SOCKET_ERRNO, "gethostname() failed", (char *) 0);
return(-1);
}
if ((ap = tet_gethostaddr(hostname)) == (struct in_addr *) 0)
return(-1);
mp->ts_addr = ntohl(ap->s_addr);
}
else
mp->ts_addr = ntohl(tp->tp_sin.sin_addr.s_addr);
pp->ptm_mtype = MT_TSINFO_IN;
pp->ptm_len = sizeof *mp;
return(0);
}
/*
** tet_tcm_ts_tsinfolen() - return length of a machine-independent
** tsinfo structure
*/
int tet_tcm_ts_tsinfolen()
{
return(TS_TSINFOSZ);
}
/*
** tet_tcm_ts_tsinfo2bs() - call tet_tsinfo2bs()
*/
int tet_tcm_ts_tsinfo2bs(from, to)
char *from, *to;
{
return(tet_tsinfo2bs((struct tsinfo *) from, to));
}
|