1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "uucp.h" 34*7c478bd9Sstevel@tonic-gate #include <rpc/trace.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #ifdef BSD4_2 37*7c478bd9Sstevel@tonic-gate #include <netdb.h> 38*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/socket.h> 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate #ifdef UNET 42*7c478bd9Sstevel@tonic-gate #include "UNET/unetio.h" 43*7c478bd9Sstevel@tonic-gate #include "UNET/tcp.h" 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate EXTERN void alarmtr(); 48*7c478bd9Sstevel@tonic-gate EXTERN jmp_buf Sjbuf; 49*7c478bd9Sstevel@tonic-gate EXTERN char *fdig(), *strecpy(); 50*7c478bd9Sstevel@tonic-gate EXTERN int interface(); 51*7c478bd9Sstevel@tonic-gate EXTERN int fd_mklock(), fd_cklock(), chat(), getdialline(); 52*7c478bd9Sstevel@tonic-gate EXTERN void fixline(), fd_rmlock(); 53*7c478bd9Sstevel@tonic-gate static void translate(); 54*7c478bd9Sstevel@tonic-gate static int gdial(); 55*7c478bd9Sstevel@tonic-gate EXTERN int Modemctrl; 56*7c478bd9Sstevel@tonic-gate EXTERN unsigned connecttime; 57*7c478bd9Sstevel@tonic-gate EXTERN int (*Setup)(); 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate extern int _fcntl(int, int, ...); 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * to add a new caller: 63*7c478bd9Sstevel@tonic-gate * declare the function that knows how to call on the device, 64*7c478bd9Sstevel@tonic-gate * add a line to the callers table giving the name of the device 65*7c478bd9Sstevel@tonic-gate * (from Devices file) and the name of the function 66*7c478bd9Sstevel@tonic-gate * add the function to the end of this file 67*7c478bd9Sstevel@tonic-gate */ 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate #ifdef DIAL801 70*7c478bd9Sstevel@tonic-gate EXTERN int dial801(); 71*7c478bd9Sstevel@tonic-gate EXTERN int open801(); 72*7c478bd9Sstevel@tonic-gate #endif 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 75*7c478bd9Sstevel@tonic-gate EXTERN int dkcall(); 76*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate #ifdef V8 79*7c478bd9Sstevel@tonic-gate int Dialout(); 80*7c478bd9Sstevel@tonic-gate #endif 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate #ifdef TCP 83*7c478bd9Sstevel@tonic-gate GLOBAL int unetcall(); 84*7c478bd9Sstevel@tonic-gate GLOBAL int tcpcall(); 85*7c478bd9Sstevel@tonic-gate #endif /* TCP */ 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 88*7c478bd9Sstevel@tonic-gate int sytcall(); 89*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate #ifdef TLI 92*7c478bd9Sstevel@tonic-gate EXTERN int tlicall(); 93*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate static struct caller Caller[] = { 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate #ifdef DIAL801 98*7c478bd9Sstevel@tonic-gate {"801", dial801}, 99*7c478bd9Sstevel@tonic-gate {"212", dial801}, 100*7c478bd9Sstevel@tonic-gate #endif /* DIAL801 */ 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate #ifdef V8 103*7c478bd9Sstevel@tonic-gate {"Dialout", Dialout}, /* ditto but using dialout(III) */ 104*7c478bd9Sstevel@tonic-gate #endif 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #ifdef TCP 107*7c478bd9Sstevel@tonic-gate #ifdef BSD4_2 108*7c478bd9Sstevel@tonic-gate {"TCP", tcpcall}, /* 4.2BSD sockets */ 109*7c478bd9Sstevel@tonic-gate #else /* !BSD4_2 */ 110*7c478bd9Sstevel@tonic-gate #ifdef UNET 111*7c478bd9Sstevel@tonic-gate {"TCP", unetcall}, /* 3com implementation of tcp */ 112*7c478bd9Sstevel@tonic-gate {"Unetserver", unetcall}, 113*7c478bd9Sstevel@tonic-gate #endif /* UNET */ 114*7c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */ 115*7c478bd9Sstevel@tonic-gate #endif /* TCP */ 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 118*7c478bd9Sstevel@tonic-gate {"DK", dkcall}, /* standard AT&T DATAKIT VCS caller */ 119*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 122*7c478bd9Sstevel@tonic-gate {"Sytek", sytcall}, /* untested but should work */ 123*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate #ifdef TLI 126*7c478bd9Sstevel@tonic-gate {"TLI", tlicall}, /* AT&T Transport Layer Interface */ 127*7c478bd9Sstevel@tonic-gate #ifdef TLIS 128*7c478bd9Sstevel@tonic-gate {"TLIS", tlicall}, /* AT&T Transport Layer Interface */ 129*7c478bd9Sstevel@tonic-gate #endif /* TLIS */ 130*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate {NULL, NULL} /* this line must be last */ 133*7c478bd9Sstevel@tonic-gate }; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* 136*7c478bd9Sstevel@tonic-gate * exphone - expand phone number for given prefix and number 137*7c478bd9Sstevel@tonic-gate * 138*7c478bd9Sstevel@tonic-gate * return code - none 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate static void 142*7c478bd9Sstevel@tonic-gate exphone(in, out) 143*7c478bd9Sstevel@tonic-gate char *in, *out; 144*7c478bd9Sstevel@tonic-gate { 145*7c478bd9Sstevel@tonic-gate FILE *fn; 146*7c478bd9Sstevel@tonic-gate char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH]; 147*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 148*7c478bd9Sstevel@tonic-gate char *s1; 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate trace1(TR_exphone, 0); 151*7c478bd9Sstevel@tonic-gate if (!isalpha(*in)) { 152*7c478bd9Sstevel@tonic-gate (void) strcpy(out, in); 153*7c478bd9Sstevel@tonic-gate trace1(TR_exphone, 1); 154*7c478bd9Sstevel@tonic-gate return; 155*7c478bd9Sstevel@tonic-gate } 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate s1=pre; 158*7c478bd9Sstevel@tonic-gate while (isalpha(*in)) 159*7c478bd9Sstevel@tonic-gate *s1++ = *in++; 160*7c478bd9Sstevel@tonic-gate *s1 = NULLCHAR; 161*7c478bd9Sstevel@tonic-gate s1 = npart; 162*7c478bd9Sstevel@tonic-gate while (*in != NULLCHAR) 163*7c478bd9Sstevel@tonic-gate *s1++ = *in++; 164*7c478bd9Sstevel@tonic-gate *s1 = NULLCHAR; 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR; 167*7c478bd9Sstevel@tonic-gate fn = fopen(DIALCODES, "r"); 168*7c478bd9Sstevel@tonic-gate if (fn != NULL) { 169*7c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fn)) { 170*7c478bd9Sstevel@tonic-gate if (sscanf(buf, "%s%s", p, tpre) < 1) 171*7c478bd9Sstevel@tonic-gate continue; 172*7c478bd9Sstevel@tonic-gate if (EQUALS(p, pre)) 173*7c478bd9Sstevel@tonic-gate break; 174*7c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR; 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate fclose(fn); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate (void) strcpy(out, tpre); 180*7c478bd9Sstevel@tonic-gate (void) strcat(out, npart); 181*7c478bd9Sstevel@tonic-gate trace1(TR_exphone, 1); 182*7c478bd9Sstevel@tonic-gate return; 183*7c478bd9Sstevel@tonic-gate } 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate /* 186*7c478bd9Sstevel@tonic-gate * repphone - Replace \D and \T sequences in arg with phone 187*7c478bd9Sstevel@tonic-gate * expanding and translating as appropriate. 188*7c478bd9Sstevel@tonic-gate */ 189*7c478bd9Sstevel@tonic-gate static char * 190*7c478bd9Sstevel@tonic-gate repphone(arg, phone, trstr) 191*7c478bd9Sstevel@tonic-gate register char *arg, *phone, *trstr; 192*7c478bd9Sstevel@tonic-gate { 193*7c478bd9Sstevel@tonic-gate static char *pbuf; /* dynamically allocated below */ 194*7c478bd9Sstevel@tonic-gate register char *fp, *tp; 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate trace1(TR_repphone, 0); 197*7c478bd9Sstevel@tonic-gate if (pbuf == NULL) { 198*7c478bd9Sstevel@tonic-gate pbuf = (char *)malloc(2*(MAXPH+2)); 199*7c478bd9Sstevel@tonic-gate if (pbuf == NULL) 200*7c478bd9Sstevel@tonic-gate return (arg); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate for (tp=pbuf; *arg; arg++) { 203*7c478bd9Sstevel@tonic-gate if (*arg != '\\') { 204*7c478bd9Sstevel@tonic-gate *tp++ = *arg; 205*7c478bd9Sstevel@tonic-gate continue; 206*7c478bd9Sstevel@tonic-gate } else { 207*7c478bd9Sstevel@tonic-gate switch (*(arg+1)) { 208*7c478bd9Sstevel@tonic-gate case 'T': 209*7c478bd9Sstevel@tonic-gate exphone(phone, tp); 210*7c478bd9Sstevel@tonic-gate translate(trstr, tp); 211*7c478bd9Sstevel@tonic-gate for (; *tp; tp++) 212*7c478bd9Sstevel@tonic-gate ; 213*7c478bd9Sstevel@tonic-gate arg++; 214*7c478bd9Sstevel@tonic-gate break; 215*7c478bd9Sstevel@tonic-gate case 'D': 216*7c478bd9Sstevel@tonic-gate for (fp=phone; *tp = *fp++; tp++) 217*7c478bd9Sstevel@tonic-gate ; 218*7c478bd9Sstevel@tonic-gate arg++; 219*7c478bd9Sstevel@tonic-gate break; 220*7c478bd9Sstevel@tonic-gate default: 221*7c478bd9Sstevel@tonic-gate *tp++ = *arg; 222*7c478bd9Sstevel@tonic-gate break; 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate *tp = '\0'; 227*7c478bd9Sstevel@tonic-gate trace1(TR_repphone, 1); 228*7c478bd9Sstevel@tonic-gate return (pbuf); 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate static u_int saved_mode; 232*7c478bd9Sstevel@tonic-gate static char saved_dcname[20]; 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate /* 235*7c478bd9Sstevel@tonic-gate * processdev - Process a line from the Devices file 236*7c478bd9Sstevel@tonic-gate * 237*7c478bd9Sstevel@tonic-gate * return codes: 238*7c478bd9Sstevel@tonic-gate * file descriptor - succeeded 239*7c478bd9Sstevel@tonic-gate * FAIL - failed 240*7c478bd9Sstevel@tonic-gate */ 241*7c478bd9Sstevel@tonic-gate GLOBAL int 242*7c478bd9Sstevel@tonic-gate processdev(flds, dev) 243*7c478bd9Sstevel@tonic-gate register char *flds[], *dev[]; 244*7c478bd9Sstevel@tonic-gate { 245*7c478bd9Sstevel@tonic-gate int dcf = -1; 246*7c478bd9Sstevel@tonic-gate register struct caller *ca; 247*7c478bd9Sstevel@tonic-gate char *args[D_MAX+1], dcname[20]; 248*7c478bd9Sstevel@tonic-gate register char **sdev; 249*7c478bd9Sstevel@tonic-gate EXTERN int pop_push(); 250*7c478bd9Sstevel@tonic-gate EXTERN void setdevcfg(); 251*7c478bd9Sstevel@tonic-gate int nullfd; 252*7c478bd9Sstevel@tonic-gate char *phonecl; /* clear phone string */ 253*7c478bd9Sstevel@tonic-gate char phoneex[2*(MAXPH+2)]; /* expanded phone string */ 254*7c478bd9Sstevel@tonic-gate EXTERN void ttygenbrk(); 255*7c478bd9Sstevel@tonic-gate struct termio tty_orig; 256*7c478bd9Sstevel@tonic-gate int ret_orig = -1; 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate trace1(TR_processdev, 0); 259*7c478bd9Sstevel@tonic-gate sdev = dev; 260*7c478bd9Sstevel@tonic-gate /* set up default "break" routine */ 261*7c478bd9Sstevel@tonic-gate genbrk = ttygenbrk; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate /* initialize Devconfig info */ 264*7c478bd9Sstevel@tonic-gate DEBUG(5, "processdev: calling setdevcfg(%s, ", Progname); 265*7c478bd9Sstevel@tonic-gate DEBUG(5, "%s)\n", flds[F_TYPE]); 266*7c478bd9Sstevel@tonic-gate setdevcfg(Progname, flds[F_TYPE]); 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate for (ca = Caller; ca->CA_type != NULL; ca++) { 269*7c478bd9Sstevel@tonic-gate /* This will find built-in caller functions */ 270*7c478bd9Sstevel@tonic-gate if (EQUALS(ca->CA_type, dev[D_CALLER])) { 271*7c478bd9Sstevel@tonic-gate DEBUG(5, "Internal caller type %s\n", dev[D_CALLER]); 272*7c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) { 273*7c478bd9Sstevel@tonic-gate /* if NULL - assume translate */ 274*7c478bd9Sstevel@tonic-gate dev[D_ARG+1] = NULL; /* needed for for loop later to mark the end */ 275*7c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\T"; 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate dev[D_ARG] = repphone(dev[D_ARG], flds[F_PHONE], ""); 278*7c478bd9Sstevel@tonic-gate if ((dcf = (*(ca->CA_caller))(flds, dev)) < 0) { 279*7c478bd9Sstevel@tonic-gate trace1(TR_processdev, 1); 280*7c478bd9Sstevel@tonic-gate return (dcf) ; 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate if (interface(ca->CA_type)) { 283*7c478bd9Sstevel@tonic-gate DEBUG(5, "interface(%s) failed", ca->CA_type); 284*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 285*7c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */ 286*7c478bd9Sstevel@tonic-gate (void)interface("UNIX"); 287*7c478bd9Sstevel@tonic-gate trace1(TR_processdev, 1); 288*7c478bd9Sstevel@tonic-gate return (FAIL); 289*7c478bd9Sstevel@tonic-gate } 290*7c478bd9Sstevel@tonic-gate dev += 2; /* Skip to next CALLER and ARG */ 291*7c478bd9Sstevel@tonic-gate break; 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate if (dcf == -1) { 295*7c478bd9Sstevel@tonic-gate /* Here if not a built-in caller function */ 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate /* We do locking (file and advisory) after open */ 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate /* 300*7c478bd9Sstevel@tonic-gate * Open the line 301*7c478bd9Sstevel@tonic-gate */ 302*7c478bd9Sstevel@tonic-gate if (*dev[D_LINE] != '/') { 303*7c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]); 304*7c478bd9Sstevel@tonic-gate } else { 305*7c478bd9Sstevel@tonic-gate (void) strcpy(dcname, dev[D_LINE]); 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate /* take care of the possible partial open fd */ 308*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); 309*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 310*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 311*7c478bd9Sstevel@tonic-gate DEBUG(1, "generic open timeout\n%s", ""); 312*7c478bd9Sstevel@tonic-gate logent("generic open", "TIMEOUT"); 313*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 314*7c478bd9Sstevel@tonic-gate goto bad; 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 317*7c478bd9Sstevel@tonic-gate (void) alarm(10); 318*7c478bd9Sstevel@tonic-gate if (Modemctrl) { 319*7c478bd9Sstevel@tonic-gate DEBUG(7, "opening with O_NDELAY set\n%s", ""); 320*7c478bd9Sstevel@tonic-gate dcf = open(dcname, (O_RDWR | O_NDELAY) ); 321*7c478bd9Sstevel@tonic-gate saved_mode = O_RDWR | O_NDELAY; 322*7c478bd9Sstevel@tonic-gate } else { 323*7c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR ); 324*7c478bd9Sstevel@tonic-gate saved_mode = O_RDWR; 325*7c478bd9Sstevel@tonic-gate } 326*7c478bd9Sstevel@tonic-gate strcpy(saved_dcname, dcname); 327*7c478bd9Sstevel@tonic-gate (void) alarm(0); 328*7c478bd9Sstevel@tonic-gate if (dcf < 0) { 329*7c478bd9Sstevel@tonic-gate DEBUG(1, "generic open failed, errno = %d\n", errno); 330*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 331*7c478bd9Sstevel@tonic-gate logent("generic open", "FAILED"); 332*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 333*7c478bd9Sstevel@tonic-gate goto bad; 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate /* check locks BEFORE modifying the stream */ 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate if (fd_mklock(dcf) != SUCCESS) { 339*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 340*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 341*7c478bd9Sstevel@tonic-gate goto bad; 342*7c478bd9Sstevel@tonic-gate } 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate if (Modemctrl) { 345*7c478bd9Sstevel@tonic-gate DEBUG(7, "clear O_NDELAY\n%s", ""); 346*7c478bd9Sstevel@tonic-gate if (_fcntl(dcf, F_SETFL, 347*7c478bd9Sstevel@tonic-gate (_fcntl(dcf, F_GETFL, 0) & ~O_NDELAY)) < 0) { 348*7c478bd9Sstevel@tonic-gate DEBUG(7, "clear O_NDELAY failed, errno %d\n", errno); 349*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 350*7c478bd9Sstevel@tonic-gate goto bad; 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate } 353*7c478bd9Sstevel@tonic-gate } 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate if ((*Setup)(MASTER, &dcf, &dcf)) { 356*7c478bd9Sstevel@tonic-gate /* any device|system lock files we should remove? */ 357*7c478bd9Sstevel@tonic-gate DEBUG(5, "MASTER Setup failed%s", ""); 358*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 359*7c478bd9Sstevel@tonic-gate goto bad; 360*7c478bd9Sstevel@tonic-gate } 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate /* configure any requested streams modules */ 363*7c478bd9Sstevel@tonic-gate if (!pop_push(dcf)) { 364*7c478bd9Sstevel@tonic-gate DEBUG(5, "STREAMS module configuration failed%s\n",""); 365*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 366*7c478bd9Sstevel@tonic-gate goto bad; 367*7c478bd9Sstevel@tonic-gate } 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate /* save initial state of line in case script fails */ 370*7c478bd9Sstevel@tonic-gate ret_orig = ioctl(dcf, TCGETA, &tty_orig); 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate /* use sdev[] since dev[] is incremented for internal callers */ 373*7c478bd9Sstevel@tonic-gate fixline(dcf, atoi(fdig(sdev[D_CLASS])), D_DIRECT); 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate /* 376*7c478bd9Sstevel@tonic-gate * Now loop through the remaining callers and chat 377*7c478bd9Sstevel@tonic-gate * according to scripts in dialers file. 378*7c478bd9Sstevel@tonic-gate */ 379*7c478bd9Sstevel@tonic-gate for (; dev[D_CALLER] != NULL; dev += 2) { 380*7c478bd9Sstevel@tonic-gate register int w; 381*7c478bd9Sstevel@tonic-gate /* 382*7c478bd9Sstevel@tonic-gate * Scan Dialers file to find an entry 383*7c478bd9Sstevel@tonic-gate */ 384*7c478bd9Sstevel@tonic-gate if ((w = gdial(dev[D_CALLER], args, D_MAX)) < 1) { 385*7c478bd9Sstevel@tonic-gate logent("generic call to gdial", "FAILED"); 386*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 387*7c478bd9Sstevel@tonic-gate goto bad; 388*7c478bd9Sstevel@tonic-gate } 389*7c478bd9Sstevel@tonic-gate if (w <= 2) /* do nothing - no chat */ 390*7c478bd9Sstevel@tonic-gate break; 391*7c478bd9Sstevel@tonic-gate /* 392*7c478bd9Sstevel@tonic-gate * Translate the phone number 393*7c478bd9Sstevel@tonic-gate */ 394*7c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) { 395*7c478bd9Sstevel@tonic-gate /* if NULL - assume no translation */ 396*7c478bd9Sstevel@tonic-gate dev[D_ARG+1] = NULL; /* needed for for loop to mark the end */ 397*7c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\D"; 398*7c478bd9Sstevel@tonic-gate } 399*7c478bd9Sstevel@tonic-gate 400*7c478bd9Sstevel@tonic-gate phonecl = repphone(dev[D_ARG], flds[F_PHONE], args[1]); 401*7c478bd9Sstevel@tonic-gate exphone(phonecl, phoneex); 402*7c478bd9Sstevel@tonic-gate translate(args[1], phoneex); 403*7c478bd9Sstevel@tonic-gate /* 404*7c478bd9Sstevel@tonic-gate * Chat 405*7c478bd9Sstevel@tonic-gate */ 406*7c478bd9Sstevel@tonic-gate if (chat(w-2, &args[2], dcf, phonecl, phoneex) != SUCCESS) { 407*7c478bd9Sstevel@tonic-gate CDEBUG(5, "\nCHAT gdial(%s) FAILED\n", dev[D_CALLER]); 408*7c478bd9Sstevel@tonic-gate Uerror = SS_CHAT_FAILED; 409*7c478bd9Sstevel@tonic-gate goto bad; 410*7c478bd9Sstevel@tonic-gate } 411*7c478bd9Sstevel@tonic-gate } 412*7c478bd9Sstevel@tonic-gate /* 413*7c478bd9Sstevel@tonic-gate * Success at last! 414*7c478bd9Sstevel@tonic-gate */ 415*7c478bd9Sstevel@tonic-gate strcpy(Dc, sdev[D_LINE]); 416*7c478bd9Sstevel@tonic-gate trace1(TR_processdev, 1); 417*7c478bd9Sstevel@tonic-gate return (dcf); 418*7c478bd9Sstevel@tonic-gate bad: 419*7c478bd9Sstevel@tonic-gate if (dcf >= 0) { 420*7c478bd9Sstevel@tonic-gate /* reset line settings if we got them in the beginning */ 421*7c478bd9Sstevel@tonic-gate if (ret_orig == 0) 422*7c478bd9Sstevel@tonic-gate (void) ioctl(dcf, TCSETAW, &tty_orig); 423*7c478bd9Sstevel@tonic-gate fd_rmlock(dcf); 424*7c478bd9Sstevel@tonic-gate (void)close(dcf); 425*7c478bd9Sstevel@tonic-gate } 426*7c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */ 427*7c478bd9Sstevel@tonic-gate (void)interface("UNIX"); 428*7c478bd9Sstevel@tonic-gate trace1(TR_processdev, 1); 429*7c478bd9Sstevel@tonic-gate return (FAIL); 430*7c478bd9Sstevel@tonic-gate } 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate /* 433*7c478bd9Sstevel@tonic-gate * clear_hup() clear the hangup state of the given device 434*7c478bd9Sstevel@tonic-gate */ 435*7c478bd9Sstevel@tonic-gate GLOBAL int 436*7c478bd9Sstevel@tonic-gate clear_hup(dcf) 437*7c478bd9Sstevel@tonic-gate int dcf; 438*7c478bd9Sstevel@tonic-gate { 439*7c478bd9Sstevel@tonic-gate int ndcf; 440*7c478bd9Sstevel@tonic-gate if ((ndcf = open(saved_dcname, saved_mode)) < 0) { 441*7c478bd9Sstevel@tonic-gate return (FAIL); 442*7c478bd9Sstevel@tonic-gate } 443*7c478bd9Sstevel@tonic-gate if (ndcf != dcf) { 444*7c478bd9Sstevel@tonic-gate close(ndcf); 445*7c478bd9Sstevel@tonic-gate } 446*7c478bd9Sstevel@tonic-gate return (SUCCESS); 447*7c478bd9Sstevel@tonic-gate } 448*7c478bd9Sstevel@tonic-gate 449*7c478bd9Sstevel@tonic-gate 450*7c478bd9Sstevel@tonic-gate /* 451*7c478bd9Sstevel@tonic-gate * translate the pairs of characters present in the first 452*7c478bd9Sstevel@tonic-gate * string whenever the first of the pair appears in the second 453*7c478bd9Sstevel@tonic-gate * string. 454*7c478bd9Sstevel@tonic-gate */ 455*7c478bd9Sstevel@tonic-gate static void 456*7c478bd9Sstevel@tonic-gate translate(ttab, str) 457*7c478bd9Sstevel@tonic-gate register char *ttab, *str; 458*7c478bd9Sstevel@tonic-gate { 459*7c478bd9Sstevel@tonic-gate register char *s; 460*7c478bd9Sstevel@tonic-gate trace1(TR_translate, 0); 461*7c478bd9Sstevel@tonic-gate 462*7c478bd9Sstevel@tonic-gate for (;*ttab && *(ttab+1); ttab += 2) 463*7c478bd9Sstevel@tonic-gate for (s=str;*s;s++) 464*7c478bd9Sstevel@tonic-gate if (*ttab == *s) 465*7c478bd9Sstevel@tonic-gate *s = *(ttab+1); 466*7c478bd9Sstevel@tonic-gate trace1(TR_translate, 1); 467*7c478bd9Sstevel@tonic-gate return; 468*7c478bd9Sstevel@tonic-gate } 469*7c478bd9Sstevel@tonic-gate 470*7c478bd9Sstevel@tonic-gate #define MAXLINE 512 471*7c478bd9Sstevel@tonic-gate /* 472*7c478bd9Sstevel@tonic-gate * Get the information about the dialer. 473*7c478bd9Sstevel@tonic-gate * gdial(type, arps, narps) 474*7c478bd9Sstevel@tonic-gate * type -> type of dialer (e.g., penril) 475*7c478bd9Sstevel@tonic-gate * arps -> array of pointers returned by gdial 476*7c478bd9Sstevel@tonic-gate * narps -> number of elements in array returned by gdial 477*7c478bd9Sstevel@tonic-gate * Return value: 478*7c478bd9Sstevel@tonic-gate * -1 -> Can't open DIALERFILE 479*7c478bd9Sstevel@tonic-gate * 0 -> requested type not found 480*7c478bd9Sstevel@tonic-gate * >0 -> success - number of fields filled in 481*7c478bd9Sstevel@tonic-gate */ 482*7c478bd9Sstevel@tonic-gate static int 483*7c478bd9Sstevel@tonic-gate gdial(type, arps, narps) 484*7c478bd9Sstevel@tonic-gate register char *type, *arps[]; 485*7c478bd9Sstevel@tonic-gate register int narps; 486*7c478bd9Sstevel@tonic-gate { 487*7c478bd9Sstevel@tonic-gate static char *info; /* dynamically allocated MAXLINE */ 488*7c478bd9Sstevel@tonic-gate int na; 489*7c478bd9Sstevel@tonic-gate EXTERN void dialreset(); 490*7c478bd9Sstevel@tonic-gate EXTERN char * currdial(); 491*7c478bd9Sstevel@tonic-gate 492*7c478bd9Sstevel@tonic-gate trace2(TR_gdial, 0, narps); 493*7c478bd9Sstevel@tonic-gate DEBUG(2, "gdial(%s) called\n", type); 494*7c478bd9Sstevel@tonic-gate if (info == NULL) { 495*7c478bd9Sstevel@tonic-gate info = (char *)malloc(MAXLINE); 496*7c478bd9Sstevel@tonic-gate if (info == NULL) { 497*7c478bd9Sstevel@tonic-gate DEBUG(1, "malloc failed for info in gdial\n", 0); 498*7c478bd9Sstevel@tonic-gate return (0); 499*7c478bd9Sstevel@tonic-gate } 500*7c478bd9Sstevel@tonic-gate } 501*7c478bd9Sstevel@tonic-gate while (getdialline(info, MAXLINE)) { 502*7c478bd9Sstevel@tonic-gate if ((info[0] == '#') || (info[0] == ' ') || 503*7c478bd9Sstevel@tonic-gate (info[0] == '\t') || (info[0] == '\n')) 504*7c478bd9Sstevel@tonic-gate continue; 505*7c478bd9Sstevel@tonic-gate if ((na = getargs(info, arps, narps)) == 0) 506*7c478bd9Sstevel@tonic-gate continue; 507*7c478bd9Sstevel@tonic-gate if (EQUALS(arps[0], type)) { 508*7c478bd9Sstevel@tonic-gate DEBUG(5, "Trying caller script '%s'", type); 509*7c478bd9Sstevel@tonic-gate DEBUG(5, " from '%s'.\n", currdial()); 510*7c478bd9Sstevel@tonic-gate dialreset(); 511*7c478bd9Sstevel@tonic-gate bsfix(arps); 512*7c478bd9Sstevel@tonic-gate trace2(TR_gdial, 1, narps); 513*7c478bd9Sstevel@tonic-gate return (na); 514*7c478bd9Sstevel@tonic-gate } 515*7c478bd9Sstevel@tonic-gate } 516*7c478bd9Sstevel@tonic-gate DEBUG(1, "%s not found in Dialers file\n", type); 517*7c478bd9Sstevel@tonic-gate dialreset(); 518*7c478bd9Sstevel@tonic-gate trace2(TR_gdial, 1, narps); 519*7c478bd9Sstevel@tonic-gate return (0); 520*7c478bd9Sstevel@tonic-gate } 521*7c478bd9Sstevel@tonic-gate 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT 524*7c478bd9Sstevel@tonic-gate 525*7c478bd9Sstevel@tonic-gate /* 526*7c478bd9Sstevel@tonic-gate * dkcall(flds, dev) make a DATAKIT VCS connection 527*7c478bd9Sstevel@tonic-gate * DATAKIT VCS is a trademark of AT&T 528*7c478bd9Sstevel@tonic-gate * 529*7c478bd9Sstevel@tonic-gate * return codes: 530*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 531*7c478bd9Sstevel@tonic-gate * FAIL - failed 532*7c478bd9Sstevel@tonic-gate */ 533*7c478bd9Sstevel@tonic-gate 534*7c478bd9Sstevel@tonic-gate #include "dk.h" 535*7c478bd9Sstevel@tonic-gate EXTERN int dkdial(); 536*7c478bd9Sstevel@tonic-gate 537*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 538*7c478bd9Sstevel@tonic-gate GLOBAL int 539*7c478bd9Sstevel@tonic-gate dkcall(flds, dev) 540*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 541*7c478bd9Sstevel@tonic-gate { 542*7c478bd9Sstevel@tonic-gate register fd; 543*7c478bd9Sstevel@tonic-gate #ifdef V8 544*7c478bd9Sstevel@tonic-gate extern int cdkp_ld; 545*7c478bd9Sstevel@tonic-gate #endif 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate char dialstring[64]; 548*7c478bd9Sstevel@tonic-gate EXTERN void dkbreak(); 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate trace1(TR_dkcall, 0); 551*7c478bd9Sstevel@tonic-gate strcpy(dialstring, dev[D_ARG]); 552*7c478bd9Sstevel@tonic-gate DEBUG(4, "dkcall(%s)\n", dialstring); 553*7c478bd9Sstevel@tonic-gate 554*7c478bd9Sstevel@tonic-gate 555*7c478bd9Sstevel@tonic-gate #ifdef V8 556*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 557*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 558*7c478bd9Sstevel@tonic-gate trace1(TR_dkcall, 1); 559*7c478bd9Sstevel@tonic-gate return (FAIL); 560*7c478bd9Sstevel@tonic-gate } 561*7c478bd9Sstevel@tonic-gate 562*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 563*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 564*7c478bd9Sstevel@tonic-gate DEBUG(4, "tdkdial(%s", flds[F_PHONE]); 565*7c478bd9Sstevel@tonic-gate DEBUG(4, ", %d)\n", atoi(dev[D_CLASS])); 566*7c478bd9Sstevel@tonic-gate if ((fd = tdkdial(flds[F_PHONE], atoi(dev[D_CLASS]))) >= 0) 567*7c478bd9Sstevel@tonic-gate if (dkproto(fd, cdkp_ld) < 0) 568*7c478bd9Sstevel@tonic-gate { 569*7c478bd9Sstevel@tonic-gate close(fd); 570*7c478bd9Sstevel@tonic-gate fd = -1; 571*7c478bd9Sstevel@tonic-gate } 572*7c478bd9Sstevel@tonic-gate (void) alarm(0); 573*7c478bd9Sstevel@tonic-gate #else 574*7c478bd9Sstevel@tonic-gate fd = dkdial(dialstring); 575*7c478bd9Sstevel@tonic-gate #endif 576*7c478bd9Sstevel@tonic-gate 577*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "DK"); 578*7c478bd9Sstevel@tonic-gate if (fd < 0) { 579*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 580*7c478bd9Sstevel@tonic-gate trace1(TR_dkcall, 1); 581*7c478bd9Sstevel@tonic-gate return (FAIL); 582*7c478bd9Sstevel@tonic-gate } 583*7c478bd9Sstevel@tonic-gate else { 584*7c478bd9Sstevel@tonic-gate genbrk = dkbreak; 585*7c478bd9Sstevel@tonic-gate trace1(TR_dkcall, 1); 586*7c478bd9Sstevel@tonic-gate return (fd); 587*7c478bd9Sstevel@tonic-gate } 588*7c478bd9Sstevel@tonic-gate } 589*7c478bd9Sstevel@tonic-gate 590*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 591*7c478bd9Sstevel@tonic-gate 592*7c478bd9Sstevel@tonic-gate #ifdef TCP 593*7c478bd9Sstevel@tonic-gate 594*7c478bd9Sstevel@tonic-gate /* 595*7c478bd9Sstevel@tonic-gate * tcpcall(flds, dev) make ethernet/socket connection 596*7c478bd9Sstevel@tonic-gate * 597*7c478bd9Sstevel@tonic-gate * return codes: 598*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 599*7c478bd9Sstevel@tonic-gate * FAIL - failed 600*7c478bd9Sstevel@tonic-gate */ 601*7c478bd9Sstevel@tonic-gate 602*7c478bd9Sstevel@tonic-gate #ifndef BSD4_2 603*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 604*7c478bd9Sstevel@tonic-gate GLOBAL int 605*7c478bd9Sstevel@tonic-gate tcpcall(flds, dev) 606*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 607*7c478bd9Sstevel@tonic-gate { 608*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 0); 609*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 610*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 1); 611*7c478bd9Sstevel@tonic-gate return (FAIL); 612*7c478bd9Sstevel@tonic-gate } 613*7c478bd9Sstevel@tonic-gate #else /* BSD4_2 */ 614*7c478bd9Sstevel@tonic-gate GLOBAL int 615*7c478bd9Sstevel@tonic-gate tcpcall(flds, dev) 616*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 617*7c478bd9Sstevel@tonic-gate { 618*7c478bd9Sstevel@tonic-gate int ret; 619*7c478bd9Sstevel@tonic-gate short port; 620*7c478bd9Sstevel@tonic-gate struct servent *sp; 621*7c478bd9Sstevel@tonic-gate struct hostent *hp; 622*7c478bd9Sstevel@tonic-gate struct sockaddr_in sin; 623*7c478bd9Sstevel@tonic-gate 624*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 0); 625*7c478bd9Sstevel@tonic-gate port = atoi(dev[D_ARG]); 626*7c478bd9Sstevel@tonic-gate if (port == 0) { 627*7c478bd9Sstevel@tonic-gate sp = getservbyname("uucp", "tcp"); 628*7c478bd9Sstevel@tonic-gate ASSERT(sp != NULL, "No uucp server", 0, 0); 629*7c478bd9Sstevel@tonic-gate port = sp->s_port; 630*7c478bd9Sstevel@tonic-gate } 631*7c478bd9Sstevel@tonic-gate else port = htons(port); 632*7c478bd9Sstevel@tonic-gate hp = gethostbyname(flds[F_NAME]); 633*7c478bd9Sstevel@tonic-gate if (hp == NULL) { 634*7c478bd9Sstevel@tonic-gate logent("tcpopen", "no such host"); 635*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 636*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 1); 637*7c478bd9Sstevel@tonic-gate return (FAIL); 638*7c478bd9Sstevel@tonic-gate } 639*7c478bd9Sstevel@tonic-gate DEBUG(4, "tcpdial host %s, ", flds[F_NAME]); 640*7c478bd9Sstevel@tonic-gate DEBUG(4, "port %d\n", ntohs(port)); 641*7c478bd9Sstevel@tonic-gate 642*7c478bd9Sstevel@tonic-gate ret = socket(AF_INET, SOCK_STREAM, 0); 643*7c478bd9Sstevel@tonic-gate if (ret < 0) { 644*7c478bd9Sstevel@tonic-gate char *errstr; 645*7c478bd9Sstevel@tonic-gate 646*7c478bd9Sstevel@tonic-gate if ((errstr = strerror(errno)) != (char *) NULL) { 647*7c478bd9Sstevel@tonic-gate DEBUG(5, "no socket: %s\n", errstr); 648*7c478bd9Sstevel@tonic-gate logent("no socket", errstr); 649*7c478bd9Sstevel@tonic-gate } 650*7c478bd9Sstevel@tonic-gate else { 651*7c478bd9Sstevel@tonic-gate DEBUG(5, "no socket, errno %d\n", errno); 652*7c478bd9Sstevel@tonic-gate logent("tcpopen", "NO SOCKET"); 653*7c478bd9Sstevel@tonic-gate } 654*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 655*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 1); 656*7c478bd9Sstevel@tonic-gate return (FAIL); 657*7c478bd9Sstevel@tonic-gate } 658*7c478bd9Sstevel@tonic-gate sin.sin_family = hp->h_addrtype; 659*7c478bd9Sstevel@tonic-gate bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); 660*7c478bd9Sstevel@tonic-gate sin.sin_port = port; 661*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 662*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tcpopen\n%s", ""); 663*7c478bd9Sstevel@tonic-gate logent("tcpopen", "TIMEOUT"); 664*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 665*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 1); 666*7c478bd9Sstevel@tonic-gate return (FAIL); 667*7c478bd9Sstevel@tonic-gate } 668*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 669*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 670*7c478bd9Sstevel@tonic-gate DEBUG(7, "family: %d\n", sin.sin_family); 671*7c478bd9Sstevel@tonic-gate DEBUG(7, "port: %d\n", sin.sin_port); 672*7c478bd9Sstevel@tonic-gate DEBUG(7, "addr: %08x\n",*((int *) &sin.sin_addr)); 673*7c478bd9Sstevel@tonic-gate if (connect(ret, (caddr_t)&sin, sizeof (sin)) < 0) { 674*7c478bd9Sstevel@tonic-gate char *errstr; 675*7c478bd9Sstevel@tonic-gate 676*7c478bd9Sstevel@tonic-gate (void) alarm(0); 677*7c478bd9Sstevel@tonic-gate (void) close(ret); 678*7c478bd9Sstevel@tonic-gate if ((errstr = strerror(errno)) != (char *) NULL) { 679*7c478bd9Sstevel@tonic-gate DEBUG(5, "connect failed: %s\n", errstr); 680*7c478bd9Sstevel@tonic-gate logent("connect failed", errstr); 681*7c478bd9Sstevel@tonic-gate } 682*7c478bd9Sstevel@tonic-gate else { 683*7c478bd9Sstevel@tonic-gate DEBUG(5, "connect failed, errno %d\n", errno); 684*7c478bd9Sstevel@tonic-gate logent("tcpopen", "CONNECT FAILED"); 685*7c478bd9Sstevel@tonic-gate } 686*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 687*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 1); 688*7c478bd9Sstevel@tonic-gate return (FAIL); 689*7c478bd9Sstevel@tonic-gate } 690*7c478bd9Sstevel@tonic-gate (void) signal(SIGPIPE, SIG_IGN); /* watch out for broken ipc link...*/ 691*7c478bd9Sstevel@tonic-gate (void) alarm(0); 692*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "IPC"); 693*7c478bd9Sstevel@tonic-gate trace1(TR_tcpcall, 1); 694*7c478bd9Sstevel@tonic-gate return (ret); 695*7c478bd9Sstevel@tonic-gate } 696*7c478bd9Sstevel@tonic-gate 697*7c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */ 698*7c478bd9Sstevel@tonic-gate 699*7c478bd9Sstevel@tonic-gate /* 700*7c478bd9Sstevel@tonic-gate * unetcall(flds, dev) make ethernet connection 701*7c478bd9Sstevel@tonic-gate * 702*7c478bd9Sstevel@tonic-gate * return codes: 703*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 704*7c478bd9Sstevel@tonic-gate * FAIL - failed 705*7c478bd9Sstevel@tonic-gate */ 706*7c478bd9Sstevel@tonic-gate 707*7c478bd9Sstevel@tonic-gate #ifndef UNET 708*7c478bd9Sstevel@tonic-gate GLOBAL int 709*7c478bd9Sstevel@tonic-gate unetcall(flds, dev) 710*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 711*7c478bd9Sstevel@tonic-gate { 712*7c478bd9Sstevel@tonic-gate trace1(TR_unetcall, 0); 713*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 714*7c478bd9Sstevel@tonic-gate trace1(TR_unetcall, 1); 715*7c478bd9Sstevel@tonic-gate return (FAIL); 716*7c478bd9Sstevel@tonic-gate } 717*7c478bd9Sstevel@tonic-gate #else /* UNET */ 718*7c478bd9Sstevel@tonic-gate GLOBAL int 719*7c478bd9Sstevel@tonic-gate unetcall(flds, dev) 720*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 721*7c478bd9Sstevel@tonic-gate { 722*7c478bd9Sstevel@tonic-gate int ret; 723*7c478bd9Sstevel@tonic-gate int port; 724*7c478bd9Sstevel@tonic-gate 725*7c478bd9Sstevel@tonic-gate trace1(TR_unetcall, 0); 726*7c478bd9Sstevel@tonic-gate port = atoi(dev[D_ARG]); 727*7c478bd9Sstevel@tonic-gate DEBUG(4, "unetdial host %s, ", flds[F_NAME]); 728*7c478bd9Sstevel@tonic-gate DEBUG(4, "port %d\n", port); 729*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 730*7c478bd9Sstevel@tonic-gate ret = tcpopen(flds[F_NAME], port, 0, TO_ACTIVE, "rw"); 731*7c478bd9Sstevel@tonic-gate (void) alarm(0); 732*7c478bd9Sstevel@tonic-gate endhnent(); 733*7c478bd9Sstevel@tonic-gate if (ret < 0) { 734*7c478bd9Sstevel@tonic-gate DEBUG(5, "tcpopen failed: errno %d\n", errno); 735*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 736*7c478bd9Sstevel@tonic-gate trace1(TR_unetcall, 1); 737*7c478bd9Sstevel@tonic-gate return (FAIL); 738*7c478bd9Sstevel@tonic-gate } 739*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "UNET"); 740*7c478bd9Sstevel@tonic-gate trace1(TR_unetcall, 1); 741*7c478bd9Sstevel@tonic-gate return (ret); 742*7c478bd9Sstevel@tonic-gate } 743*7c478bd9Sstevel@tonic-gate #endif /* UNET */ 744*7c478bd9Sstevel@tonic-gate 745*7c478bd9Sstevel@tonic-gate #endif /* TCP */ 746*7c478bd9Sstevel@tonic-gate 747*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 748*7c478bd9Sstevel@tonic-gate 749*7c478bd9Sstevel@tonic-gate /* 750*7c478bd9Sstevel@tonic-gate * sytcall(flds, dev) make a sytek connection 751*7c478bd9Sstevel@tonic-gate * 752*7c478bd9Sstevel@tonic-gate * return codes: 753*7c478bd9Sstevel@tonic-gate * >0 - file number - ok 754*7c478bd9Sstevel@tonic-gate * FAIL - failed 755*7c478bd9Sstevel@tonic-gate */ 756*7c478bd9Sstevel@tonic-gate 757*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 758*7c478bd9Sstevel@tonic-gate GLOBAL int 759*7c478bd9Sstevel@tonic-gate sytcall(flds, dev) 760*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 761*7c478bd9Sstevel@tonic-gate { 762*7c478bd9Sstevel@tonic-gate int dcr, dcr2, nullfd, ret; 763*7c478bd9Sstevel@tonic-gate char dcname[20], command[BUFSIZ]; 764*7c478bd9Sstevel@tonic-gate 765*7c478bd9Sstevel@tonic-gate 766*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 0); 767*7c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]); 768*7c478bd9Sstevel@tonic-gate DEBUG(4, "dc - %s, ", dcname); 769*7c478bd9Sstevel@tonic-gate dcr = open(dcname, O_WRONLY|O_NDELAY); 770*7c478bd9Sstevel@tonic-gate if (dcr < 0) { 771*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 772*7c478bd9Sstevel@tonic-gate DEBUG(4, "OPEN FAILED %s\n", dcname); 773*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 1); 774*7c478bd9Sstevel@tonic-gate return (FAIL); 775*7c478bd9Sstevel@tonic-gate } 776*7c478bd9Sstevel@tonic-gate if (fd_mklock(dcr) != SUCCESS) { 777*7c478bd9Sstevel@tonic-gate (void)close(dcr); 778*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 779*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 780*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 1); 781*7c478bd9Sstevel@tonic-gate return (FAIL); 782*7c478bd9Sstevel@tonic-gate } 783*7c478bd9Sstevel@tonic-gate 784*7c478bd9Sstevel@tonic-gate sytfixline(dcr, atoi(fdig(dev[D_CLASS])), D_DIRECT); 785*7c478bd9Sstevel@tonic-gate (void) sleep(2); 786*7c478bd9Sstevel@tonic-gate DEBUG(4, "Calling Sytek unit %s\n", dev[D_ARG]); 787*7c478bd9Sstevel@tonic-gate (void) sprintf(command,"\r\rcall %s\r", dev[D_ARG]); 788*7c478bd9Sstevel@tonic-gate ret = (*Write)(dcr, command, strlen(command)); 789*7c478bd9Sstevel@tonic-gate (void) sleep(1); 790*7c478bd9Sstevel@tonic-gate DEBUG(4, "COM1 return = %d\n", ret); 791*7c478bd9Sstevel@tonic-gate sytfix2line(dcr); 792*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); 793*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 794*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 795*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout sytek open\n%s", ""); 796*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 797*7c478bd9Sstevel@tonic-gate (void) close(dcr2); 798*7c478bd9Sstevel@tonic-gate fd_rmlock(dcr); 799*7c478bd9Sstevel@tonic-gate (void) close(dcr); 800*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 801*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 1); 802*7c478bd9Sstevel@tonic-gate return (FAIL); 803*7c478bd9Sstevel@tonic-gate } 804*7c478bd9Sstevel@tonic-gate (void) alarm(10); 805*7c478bd9Sstevel@tonic-gate dcr2 = open(dcname,O_RDWR); 806*7c478bd9Sstevel@tonic-gate (void) alarm(0); 807*7c478bd9Sstevel@tonic-gate fd_rmlock(dcr); 808*7c478bd9Sstevel@tonic-gate (void) close(dcr); 809*7c478bd9Sstevel@tonic-gate if (dcr2 < 0) { 810*7c478bd9Sstevel@tonic-gate DEBUG(4, "OPEN 2 FAILED %s\n", dcname); 811*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 812*7c478bd9Sstevel@tonic-gate (void) close(nullfd); /* kernel might think dc2 is open */ 813*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 1); 814*7c478bd9Sstevel@tonic-gate return (FAIL); 815*7c478bd9Sstevel@tonic-gate } 816*7c478bd9Sstevel@tonic-gate if (fd_mklock(dcr2) != SUCCESS) { 817*7c478bd9Sstevel@tonic-gate (void)close(dcr2); 818*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 819*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 820*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 1); 821*7c478bd9Sstevel@tonic-gate return (FAIL); 822*7c478bd9Sstevel@tonic-gate } 823*7c478bd9Sstevel@tonic-gate trace1(TR_sytcall, 1); 824*7c478bd9Sstevel@tonic-gate return (dcr2); 825*7c478bd9Sstevel@tonic-gate } 826*7c478bd9Sstevel@tonic-gate 827*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 828*7c478bd9Sstevel@tonic-gate 829*7c478bd9Sstevel@tonic-gate #ifdef DIAL801 830*7c478bd9Sstevel@tonic-gate 831*7c478bd9Sstevel@tonic-gate /* 832*7c478bd9Sstevel@tonic-gate * dial801(flds, dev) dial remote machine on 801/801 833*7c478bd9Sstevel@tonic-gate * char *flds[], *dev[]; 834*7c478bd9Sstevel@tonic-gate * 835*7c478bd9Sstevel@tonic-gate * return codes: 836*7c478bd9Sstevel@tonic-gate * file descriptor - succeeded 837*7c478bd9Sstevel@tonic-gate * FAIL - failed 838*7c478bd9Sstevel@tonic-gate * 839*7c478bd9Sstevel@tonic-gate * unfortunately, open801() is different for usg and non-usg 840*7c478bd9Sstevel@tonic-gate */ 841*7c478bd9Sstevel@tonic-gate 842*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 843*7c478bd9Sstevel@tonic-gate GLOBAL int 844*7c478bd9Sstevel@tonic-gate dial801(flds, dev) 845*7c478bd9Sstevel@tonic-gate char *flds[], *dev[]; 846*7c478bd9Sstevel@tonic-gate { 847*7c478bd9Sstevel@tonic-gate char dcname[20], dnname[20], phone[MAXPH+2]; 848*7c478bd9Sstevel@tonic-gate int dcf = -1, speed; 849*7c478bd9Sstevel@tonic-gate 850*7c478bd9Sstevel@tonic-gate trace1(TR_dial801, 0); 851*7c478bd9Sstevel@tonic-gate (void) sprintf(dnname, "/dev/%s", dev[D_CALLDEV]); 852*7c478bd9Sstevel@tonic-gate (void) sprintf(phone, "%s%s", dev[D_ARG] , ACULAST); 853*7c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]); 854*7c478bd9Sstevel@tonic-gate CDEBUG(1, "Use Port %s, ", dcname); 855*7c478bd9Sstevel@tonic-gate DEBUG(4, "acu - %s, ", dnname); 856*7c478bd9Sstevel@tonic-gate VERBOSE("Trying modem - %s, ", dcname); /* for cu */ 857*7c478bd9Sstevel@tonic-gate VERBOSE("acu - %s, ", dnname); /* for cu */ 858*7c478bd9Sstevel@tonic-gate if (getuid()==0 || GRPCHK(getgid())) { 859*7c478bd9Sstevel@tonic-gate CDEBUG(1, "Phone Number %s\n", phone); 860*7c478bd9Sstevel@tonic-gate /* In cu, only give out the phone number to trusted people. */ 861*7c478bd9Sstevel@tonic-gate VERBOSE("calling %s: ", phone); /* for cu */ 862*7c478bd9Sstevel@tonic-gate } 863*7c478bd9Sstevel@tonic-gate speed = atoi(fdig(dev[D_CLASS])); 864*7c478bd9Sstevel@tonic-gate dcf = open801(dcname, dnname, phone, speed); 865*7c478bd9Sstevel@tonic-gate if (dcf >= 0) { 866*7c478bd9Sstevel@tonic-gate if (fd_mklock(dcf) != SUCCESS) { 867*7c478bd9Sstevel@tonic-gate (void) close(dcf); 868*7c478bd9Sstevel@tonic-gate DEBUG(5, "fd_mklock line %s failed\n", dev[D_LINE]); 869*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 870*7c478bd9Sstevel@tonic-gate trace1(TR_dial801, 1); 871*7c478bd9Sstevel@tonic-gate return (FAIL); 872*7c478bd9Sstevel@tonic-gate } 873*7c478bd9Sstevel@tonic-gate fixline(dcf, speed, D_ACU); 874*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_LINE]); /* for later unlock() */ 875*7c478bd9Sstevel@tonic-gate VERBOSE("SUCCEEDED\n%s", ""); 876*7c478bd9Sstevel@tonic-gate } else { 877*7c478bd9Sstevel@tonic-gate VERBOSE("FAILED\n%s", ""); 878*7c478bd9Sstevel@tonic-gate } 879*7c478bd9Sstevel@tonic-gate trace1(TR_dial801, 1); 880*7c478bd9Sstevel@tonic-gate return (dcf); 881*7c478bd9Sstevel@tonic-gate } 882*7c478bd9Sstevel@tonic-gate 883*7c478bd9Sstevel@tonic-gate 884*7c478bd9Sstevel@tonic-gate #ifndef ATTSV 885*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 886*7c478bd9Sstevel@tonic-gate GLOBAL int 887*7c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed) 888*7c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone; 889*7c478bd9Sstevel@tonic-gate { 890*7c478bd9Sstevel@tonic-gate int nw, lt, dcf = -1, nullfd, dnf = -1; 891*7c478bd9Sstevel@tonic-gate pid_t w_ret, pid = -1; 892*7c478bd9Sstevel@tonic-gate unsigned timelim; 893*7c478bd9Sstevel@tonic-gate 894*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 0); 895*7c478bd9Sstevel@tonic-gate if ((dnf = open(dnname, O_WRONLY)) < 0) { 896*7c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dnname); 897*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 898*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 899*7c478bd9Sstevel@tonic-gate return (FAIL); 900*7c478bd9Sstevel@tonic-gate } 901*7c478bd9Sstevel@tonic-gate DEBUG(5, "%s is open\n", dnname); 902*7c478bd9Sstevel@tonic-gate 903*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/dev/null", O_RDONLY));/* partial open hack */ 904*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 905*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout modem open\n%s", ""); 906*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 907*7c478bd9Sstevel@tonic-gate (void) close(dcf); 908*7c478bd9Sstevel@tonic-gate (void) close(dnf); 909*7c478bd9Sstevel@tonic-gate logent("801 open", "TIMEOUT"); 910*7c478bd9Sstevel@tonic-gate if (pid > 0) { 911*7c478bd9Sstevel@tonic-gate kill(pid, 9); 912*7c478bd9Sstevel@tonic-gate wait((int *) 0); 913*7c478bd9Sstevel@tonic-gate } 914*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 915*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 916*7c478bd9Sstevel@tonic-gate return (FAIL); 917*7c478bd9Sstevel@tonic-gate } 918*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 919*7c478bd9Sstevel@tonic-gate timelim = 5 * strlen(phone); 920*7c478bd9Sstevel@tonic-gate (void) alarm(timelim < connecttime ? connecttime : timelim); 921*7c478bd9Sstevel@tonic-gate if ((pid = fork()) == 0) { 922*7c478bd9Sstevel@tonic-gate sleep(2); 923*7c478bd9Sstevel@tonic-gate nw = (*Write)(dnf, phone, lt = strlen(phone)); 924*7c478bd9Sstevel@tonic-gate if (nw != lt) { 925*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write error %d\n", errno); 926*7c478bd9Sstevel@tonic-gate logent("ACU write", "FAILED"); 927*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 928*7c478bd9Sstevel@tonic-gate exit(1); 929*7c478bd9Sstevel@tonic-gate } 930*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write ok\n%s", ""); 931*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 932*7c478bd9Sstevel@tonic-gate exit(0); 933*7c478bd9Sstevel@tonic-gate } 934*7c478bd9Sstevel@tonic-gate /* open line - will return on carrier */ 935*7c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR); 936*7c478bd9Sstevel@tonic-gate 937*7c478bd9Sstevel@tonic-gate DEBUG(4, "dcf is %d\n", dcf); 938*7c478bd9Sstevel@tonic-gate if (dcf < 0) { /* handle like a timeout */ 939*7c478bd9Sstevel@tonic-gate (void) alarm(0); 940*7c478bd9Sstevel@tonic-gate longjmp(Sjbuf, 1); 941*7c478bd9Sstevel@tonic-gate } 942*7c478bd9Sstevel@tonic-gate 943*7c478bd9Sstevel@tonic-gate /* modem is open */ 944*7c478bd9Sstevel@tonic-gate while ((w_ret = wait(<)) != pid) 945*7c478bd9Sstevel@tonic-gate if (w_ret == -1 && errno != EINTR) { 946*7c478bd9Sstevel@tonic-gate DEBUG(4, "Wait failed errno=%d\n", errno); 947*7c478bd9Sstevel@tonic-gate (void) close(dcf); 948*7c478bd9Sstevel@tonic-gate (void) close(dnf); 949*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 950*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 951*7c478bd9Sstevel@tonic-gate return (FAIL); 952*7c478bd9Sstevel@tonic-gate } 953*7c478bd9Sstevel@tonic-gate (void) alarm(0); 954*7c478bd9Sstevel@tonic-gate 955*7c478bd9Sstevel@tonic-gate (void) close(dnf); /* no reason to keep the 801 open */ 956*7c478bd9Sstevel@tonic-gate if (lt != 0) { 957*7c478bd9Sstevel@tonic-gate DEBUG(4, "Fork Stat %o\n", lt); 958*7c478bd9Sstevel@tonic-gate (void) close(dcf); 959*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 960*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 961*7c478bd9Sstevel@tonic-gate return (FAIL); 962*7c478bd9Sstevel@tonic-gate } 963*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 964*7c478bd9Sstevel@tonic-gate return (dcf); 965*7c478bd9Sstevel@tonic-gate } 966*7c478bd9Sstevel@tonic-gate 967*7c478bd9Sstevel@tonic-gate #else /* ATTSV */ 968*7c478bd9Sstevel@tonic-gate 969*7c478bd9Sstevel@tonic-gate GLOBAL int 970*7c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed) 971*7c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone; 972*7c478bd9Sstevel@tonic-gate { 973*7c478bd9Sstevel@tonic-gate int nw, lt, dcf = -1, nullfd, dnf = -1, ret; 974*7c478bd9Sstevel@tonic-gate unsigned timelim; 975*7c478bd9Sstevel@tonic-gate 976*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 0); 977*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); /* partial open hack */ 978*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 979*7c478bd9Sstevel@tonic-gate DEBUG(4, "DN write %s\n", "timeout"); 980*7c478bd9Sstevel@tonic-gate (void) close(dnf); 981*7c478bd9Sstevel@tonic-gate (void) close(dcf); 982*7c478bd9Sstevel@tonic-gate (void) close(nullfd); 983*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 984*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 985*7c478bd9Sstevel@tonic-gate return (FAIL); 986*7c478bd9Sstevel@tonic-gate } 987*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 988*7c478bd9Sstevel@tonic-gate timelim = 5 * strlen(phone); 989*7c478bd9Sstevel@tonic-gate (void) alarm(timelim < connecttime ? connecttime : timelim); 990*7c478bd9Sstevel@tonic-gate 991*7c478bd9Sstevel@tonic-gate if ((dnf = open(dnname, O_WRONLY)) < 0) { 992*7c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dnname); 993*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 994*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 995*7c478bd9Sstevel@tonic-gate return (FAIL); 996*7c478bd9Sstevel@tonic-gate } 997*7c478bd9Sstevel@tonic-gate DEBUG(5, "%s is open\n", dnname); 998*7c478bd9Sstevel@tonic-gate if (fd_mklock(dnf) != SUCCESS) { 999*7c478bd9Sstevel@tonic-gate (void)close(dnf); 1000*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dnname); 1001*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 1002*7c478bd9Sstevel@tonic-gate } 1003*7c478bd9Sstevel@tonic-gate if ((dcf = open(dcname, O_RDWR | O_NDELAY)) < 0) { 1004*7c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dcname); 1005*7c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE; 1006*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 1007*7c478bd9Sstevel@tonic-gate return (FAIL); 1008*7c478bd9Sstevel@tonic-gate } 1009*7c478bd9Sstevel@tonic-gate if (fd_mklock(dcf) != SUCCESS) { 1010*7c478bd9Sstevel@tonic-gate (void)close(dcf); 1011*7c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname); 1012*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 1013*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 1014*7c478bd9Sstevel@tonic-gate return (FAIL); 1015*7c478bd9Sstevel@tonic-gate } 1016*7c478bd9Sstevel@tonic-gate 1017*7c478bd9Sstevel@tonic-gate DEBUG(4, "dcf is %d\n", dcf); 1018*7c478bd9Sstevel@tonic-gate fixline(dcf, speed, D_ACU); 1019*7c478bd9Sstevel@tonic-gate nw = (*Write)(dnf, phone, lt = strlen(phone)); 1020*7c478bd9Sstevel@tonic-gate if (nw != lt) { 1021*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1022*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write error %d\n", errno); 1023*7c478bd9Sstevel@tonic-gate (void) close(dnf); 1024*7c478bd9Sstevel@tonic-gate (void) close(dcf); 1025*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1026*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 1027*7c478bd9Sstevel@tonic-gate return (FAIL); 1028*7c478bd9Sstevel@tonic-gate } else 1029*7c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write ok\n%s", ""); 1030*7c478bd9Sstevel@tonic-gate 1031*7c478bd9Sstevel@tonic-gate (void) close(dnf); 1032*7c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); /* partial open hack */ 1033*7c478bd9Sstevel@tonic-gate ret = open(dcname, O_RDWR); /* wait for carrier */ 1034*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1035*7c478bd9Sstevel@tonic-gate (void) close(ret); /* close 2nd modem open() */ 1036*7c478bd9Sstevel@tonic-gate if (ret < 0) { /* open() interrupted by alarm */ 1037*7c478bd9Sstevel@tonic-gate DEBUG(4, "Line open %s\n", "failed"); 1038*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1039*7c478bd9Sstevel@tonic-gate (void) close(nullfd); /* close partially opened modem */ 1040*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 1041*7c478bd9Sstevel@tonic-gate return (FAIL); 1042*7c478bd9Sstevel@tonic-gate } 1043*7c478bd9Sstevel@tonic-gate (void) _fcntl(dcf,F_SETFL, _fcntl(dcf, F_GETFL, 0) & ~O_NDELAY); 1044*7c478bd9Sstevel@tonic-gate trace1(TR_open801, 1); 1045*7c478bd9Sstevel@tonic-gate return (dcf); 1046*7c478bd9Sstevel@tonic-gate } 1047*7c478bd9Sstevel@tonic-gate #endif /* ATTSV */ 1048*7c478bd9Sstevel@tonic-gate 1049*7c478bd9Sstevel@tonic-gate #endif /* DIAL801 */ 1050*7c478bd9Sstevel@tonic-gate 1051*7c478bd9Sstevel@tonic-gate #ifdef V8 1052*7c478bd9Sstevel@tonic-gate GLOBAL int 1053*7c478bd9Sstevel@tonic-gate Dialout(flds) 1054*7c478bd9Sstevel@tonic-gate char *flds[]; 1055*7c478bd9Sstevel@tonic-gate { 1056*7c478bd9Sstevel@tonic-gate int fd; 1057*7c478bd9Sstevel@tonic-gate char phone[MAXPH+2]; 1058*7c478bd9Sstevel@tonic-gate 1059*7c478bd9Sstevel@tonic-gate 1060*7c478bd9Sstevel@tonic-gate trace1(TR_Dialout, 0); 1061*7c478bd9Sstevel@tonic-gate exphone(flds[F_PHONE], phone); 1062*7c478bd9Sstevel@tonic-gate 1063*7c478bd9Sstevel@tonic-gate DEBUG(4, "call dialout(%s", phone); 1064*7c478bd9Sstevel@tonic-gate DEBUG(4, ", %s)\n", dev[D_CLASS]); 1065*7c478bd9Sstevel@tonic-gate fd = dialout(phone, dev[D_CLASS]); 1066*7c478bd9Sstevel@tonic-gate if (fd == -1) 1067*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1068*7c478bd9Sstevel@tonic-gate if (fd == -3) 1069*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1070*7c478bd9Sstevel@tonic-gate if (fd == -9) 1071*7c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED; 1072*7c478bd9Sstevel@tonic-gate 1073*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "Dialout"); 1074*7c478bd9Sstevel@tonic-gate 1075*7c478bd9Sstevel@tonic-gate trace1(TR_Dialout, 1); 1076*7c478bd9Sstevel@tonic-gate return (fd); 1077*7c478bd9Sstevel@tonic-gate } 1078*7c478bd9Sstevel@tonic-gate #endif /* V8 */ 1079*7c478bd9Sstevel@tonic-gate 1080*7c478bd9Sstevel@tonic-gate #ifdef TLI 1081*7c478bd9Sstevel@tonic-gate /* 1082*7c478bd9Sstevel@tonic-gate * 1083*7c478bd9Sstevel@tonic-gate * AT&T Transport Layer Interface 1084*7c478bd9Sstevel@tonic-gate * 1085*7c478bd9Sstevel@tonic-gate * expected in Devices 1086*7c478bd9Sstevel@tonic-gate * TLI line1 - - TLI 1087*7c478bd9Sstevel@tonic-gate * or 1088*7c478bd9Sstevel@tonic-gate * TLIS line1 - - TLIS 1089*7c478bd9Sstevel@tonic-gate * 1090*7c478bd9Sstevel@tonic-gate */ 1091*7c478bd9Sstevel@tonic-gate 1092*7c478bd9Sstevel@tonic-gate #include <tiuser.h> 1093*7c478bd9Sstevel@tonic-gate 1094*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 1095*7c478bd9Sstevel@tonic-gate EXTERN void tfaillog(int fd, const char *s); 1096*7c478bd9Sstevel@tonic-gate #else 1097*7c478bd9Sstevel@tonic-gate EXTERN void tfaillog(); 1098*7c478bd9Sstevel@tonic-gate #endif 1099*7c478bd9Sstevel@tonic-gate 1100*7c478bd9Sstevel@tonic-gate char *t_alloc(); 1101*7c478bd9Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis(); 1102*7c478bd9Sstevel@tonic-gate 1103*7c478bd9Sstevel@tonic-gate #define CONNECT_ATTEMPTS 3 1104*7c478bd9Sstevel@tonic-gate #define TFREE(p, type) if ((p)) t_free((char *)(p), (type)) 1105*7c478bd9Sstevel@tonic-gate 1106*7c478bd9Sstevel@tonic-gate /* 1107*7c478bd9Sstevel@tonic-gate * returns fd to remote uucp daemon 1108*7c478bd9Sstevel@tonic-gate */ 1109*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1110*7c478bd9Sstevel@tonic-gate GLOBAL int 1111*7c478bd9Sstevel@tonic-gate tlicall(flds, dev) 1112*7c478bd9Sstevel@tonic-gate char *flds[]; 1113*7c478bd9Sstevel@tonic-gate char *dev[]; 1114*7c478bd9Sstevel@tonic-gate { 1115*7c478bd9Sstevel@tonic-gate char addrbuf[ BUFSIZ ]; 1116*7c478bd9Sstevel@tonic-gate char devname[MAXNAMESIZE]; 1117*7c478bd9Sstevel@tonic-gate int fd; 1118*7c478bd9Sstevel@tonic-gate register int i, j; 1119*7c478bd9Sstevel@tonic-gate struct t_bind *bind_ret = 0; 1120*7c478bd9Sstevel@tonic-gate struct t_info tinfo; 1121*7c478bd9Sstevel@tonic-gate struct t_call *sndcall = 0, *rcvcall = 0; 1122*7c478bd9Sstevel@tonic-gate 1123*7c478bd9Sstevel@tonic-gate EXTERN struct netbuf *stoa(); 1124*7c478bd9Sstevel@tonic-gate 1125*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 0); 1126*7c478bd9Sstevel@tonic-gate if (dev[D_LINE][0] != '/') { 1127*7c478bd9Sstevel@tonic-gate /* dev holds device name relative to /dev */ 1128*7c478bd9Sstevel@tonic-gate sprintf(devname, "/dev/%s", dev[D_LINE]); 1129*7c478bd9Sstevel@tonic-gate } else { 1130*7c478bd9Sstevel@tonic-gate /* dev holds full path name of device */ 1131*7c478bd9Sstevel@tonic-gate strcpy(devname, dev[D_LINE]); 1132*7c478bd9Sstevel@tonic-gate } 1133*7c478bd9Sstevel@tonic-gate /* gimme local transport endpoint */ 1134*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1135*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 1136*7c478bd9Sstevel@tonic-gate DEBUG(1, "t_open timeout\n%s", ""); 1137*7c478bd9Sstevel@tonic-gate logent("t_open", "TIMEOUT"); 1138*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1139*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1140*7c478bd9Sstevel@tonic-gate return (FAIL); 1141*7c478bd9Sstevel@tonic-gate } 1142*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 1143*7c478bd9Sstevel@tonic-gate (void) alarm(5); 1144*7c478bd9Sstevel@tonic-gate fd = t_open(devname, O_RDWR, &tinfo); 1145*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1146*7c478bd9Sstevel@tonic-gate if (fd < 0) { 1147*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_open"); 1148*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1149*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1150*7c478bd9Sstevel@tonic-gate return (FAIL); 1151*7c478bd9Sstevel@tonic-gate } 1152*7c478bd9Sstevel@tonic-gate if (fd_mklock(fd) != SUCCESS) { 1153*7c478bd9Sstevel@tonic-gate (void)t_close(fd); 1154*7c478bd9Sstevel@tonic-gate DEBUG(1, "tlicall: failed to lock device %s\n", devname); 1155*7c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE; 1156*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1157*7c478bd9Sstevel@tonic-gate return (FAIL); 1158*7c478bd9Sstevel@tonic-gate } 1159*7c478bd9Sstevel@tonic-gate 1160*7c478bd9Sstevel@tonic-gate /* allocate tli structures */ 1161*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1162*7c478bd9Sstevel@tonic-gate if ((bind_ret = (struct t_bind *)t_alloc(fd, T_BIND, T_ALL)) == 1163*7c478bd9Sstevel@tonic-gate (struct t_bind *)NULL 1164*7c478bd9Sstevel@tonic-gate || (sndcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == 1165*7c478bd9Sstevel@tonic-gate (struct t_call *)NULL 1166*7c478bd9Sstevel@tonic-gate || (rcvcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == 1167*7c478bd9Sstevel@tonic-gate (struct t_call *)NULL) { 1168*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_alloc"); 1169*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1170*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1171*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1172*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1173*7c478bd9Sstevel@tonic-gate return (FAIL); 1174*7c478bd9Sstevel@tonic-gate } 1175*7c478bd9Sstevel@tonic-gate 1176*7c478bd9Sstevel@tonic-gate /* bind */ 1177*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1178*7c478bd9Sstevel@tonic-gate if (t_bind(fd, (struct t_bind *) 0, bind_ret) < 0) { 1179*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_bind"); 1180*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1181*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1182*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1183*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1184*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1185*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1186*7c478bd9Sstevel@tonic-gate return (FAIL); 1187*7c478bd9Sstevel@tonic-gate } 1188*7c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: bound to %s\n", bind_ret->addr.buf); 1189*7c478bd9Sstevel@tonic-gate 1190*7c478bd9Sstevel@tonic-gate /* 1191*7c478bd9Sstevel@tonic-gate * Prepare to connect. 1192*7c478bd9Sstevel@tonic-gate * 1193*7c478bd9Sstevel@tonic-gate * If address begins with "\x", "\X", "\o", or "\O", 1194*7c478bd9Sstevel@tonic-gate * assume is hexadecimal or octal address and use stoa() 1195*7c478bd9Sstevel@tonic-gate * to convert it. 1196*7c478bd9Sstevel@tonic-gate * 1197*7c478bd9Sstevel@tonic-gate * Else is usual uucico address -- only \N's left to process. 1198*7c478bd9Sstevel@tonic-gate * Walk thru connection address, changing \N's to NULLCHARs. 1199*7c478bd9Sstevel@tonic-gate * Note: If a NULLCHAR must be part of the connection address, 1200*7c478bd9Sstevel@tonic-gate * it must be overtly included in the address. One recommended 1201*7c478bd9Sstevel@tonic-gate * way is to do it in the Devices file, thusly: 1202*7c478bd9Sstevel@tonic-gate * Netname /dev/netport - - TLI \D\000 1203*7c478bd9Sstevel@tonic-gate * bsfix() turns \000 into \N and then the loop below makes it a 1204*7c478bd9Sstevel@tonic-gate * real, included-in-the-length null-byte. 1205*7c478bd9Sstevel@tonic-gate * 1206*7c478bd9Sstevel@tonic-gate * The DEBUG must print the strecpy'd address (so that 1207*7c478bd9Sstevel@tonic-gate * non-printables will have been replaced with C escapes). 1208*7c478bd9Sstevel@tonic-gate */ 1209*7c478bd9Sstevel@tonic-gate 1210*7c478bd9Sstevel@tonic-gate DEBUG(5, "t_connect to addr \"%s\"\n", 1211*7c478bd9Sstevel@tonic-gate strecpy(addrbuf, dev[D_ARG], "\\")); 1212*7c478bd9Sstevel@tonic-gate 1213*7c478bd9Sstevel@tonic-gate if (dev[D_ARG][0] == '\\' && 1214*7c478bd9Sstevel@tonic-gate (dev[D_ARG][1] == 'x' || dev[D_ARG][1] == 'X' 1215*7c478bd9Sstevel@tonic-gate || dev[D_ARG][1] == 'o' || dev[D_ARG][1] == 'O')) { 1216*7c478bd9Sstevel@tonic-gate if (stoa(dev[D_ARG], &(sndcall->addr)) == (struct netbuf *)NULL) { 1217*7c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: stoa failed\n%s", ""); 1218*7c478bd9Sstevel@tonic-gate logent("tlicall", "string-to-address failed"); 1219*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1220*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1221*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1222*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1223*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1224*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1225*7c478bd9Sstevel@tonic-gate return (FAIL); 1226*7c478bd9Sstevel@tonic-gate } 1227*7c478bd9Sstevel@tonic-gate } else { 1228*7c478bd9Sstevel@tonic-gate for (i = j = 0; i < BUFSIZ && dev[D_ARG][i] != NULLCHAR; 1229*7c478bd9Sstevel@tonic-gate ++i, ++j) { 1230*7c478bd9Sstevel@tonic-gate if (dev[D_ARG][i] == '\\' && dev[D_ARG][i+1] == 'N') { 1231*7c478bd9Sstevel@tonic-gate addrbuf[j] = NULLCHAR; 1232*7c478bd9Sstevel@tonic-gate ++i; 1233*7c478bd9Sstevel@tonic-gate } 1234*7c478bd9Sstevel@tonic-gate else { 1235*7c478bd9Sstevel@tonic-gate addrbuf[j] = dev[D_ARG][i]; 1236*7c478bd9Sstevel@tonic-gate } 1237*7c478bd9Sstevel@tonic-gate } 1238*7c478bd9Sstevel@tonic-gate sndcall->addr.buf = addrbuf; 1239*7c478bd9Sstevel@tonic-gate sndcall->addr.len = j; 1240*7c478bd9Sstevel@tonic-gate } 1241*7c478bd9Sstevel@tonic-gate 1242*7c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) { 1243*7c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tlicall\n%s", ""); 1244*7c478bd9Sstevel@tonic-gate logent("tlicall", "TIMEOUT"); 1245*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1246*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1247*7c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1248*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1249*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1250*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1251*7c478bd9Sstevel@tonic-gate return (FAIL); 1252*7c478bd9Sstevel@tonic-gate } 1253*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 1254*7c478bd9Sstevel@tonic-gate (void) alarm(connecttime); 1255*7c478bd9Sstevel@tonic-gate 1256*7c478bd9Sstevel@tonic-gate /* connect to the service -- some listeners can't handle */ 1257*7c478bd9Sstevel@tonic-gate /* multiple connect requests, so try it a few times */ 1258*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1259*7c478bd9Sstevel@tonic-gate for (i = 0; i < CONNECT_ATTEMPTS; ++i) { 1260*7c478bd9Sstevel@tonic-gate if (t_connect(fd, sndcall, rcvcall) == 0) 1261*7c478bd9Sstevel@tonic-gate break; 1262*7c478bd9Sstevel@tonic-gate if ((t_errno == TLOOK) && (t_look(fd) == T_DISCONNECT)) { 1263*7c478bd9Sstevel@tonic-gate t_rcvdis(fd,NULL); 1264*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1265*7c478bd9Sstevel@tonic-gate } else { 1266*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1267*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect"); 1268*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1269*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1270*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1271*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1272*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1273*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1274*7c478bd9Sstevel@tonic-gate return (FAIL); 1275*7c478bd9Sstevel@tonic-gate } 1276*7c478bd9Sstevel@tonic-gate } 1277*7c478bd9Sstevel@tonic-gate (void) alarm(0); 1278*7c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL); 1279*7c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL); 1280*7c478bd9Sstevel@tonic-gate if (i == CONNECT_ATTEMPTS) { 1281*7c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect"); 1282*7c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED; 1283*7c478bd9Sstevel@tonic-gate fd_rmlock(fd); 1284*7c478bd9Sstevel@tonic-gate (void) t_close(fd); 1285*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1286*7c478bd9Sstevel@tonic-gate return (FAIL); 1287*7c478bd9Sstevel@tonic-gate } 1288*7c478bd9Sstevel@tonic-gate errno = t_errno = 0; 1289*7c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_CALLER]); 1290*7c478bd9Sstevel@tonic-gate trace1(TR_tlicall, 1); 1291*7c478bd9Sstevel@tonic-gate return (fd); 1292*7c478bd9Sstevel@tonic-gate } 1293*7c478bd9Sstevel@tonic-gate #endif /* TLI */ 1294