xref: /illumos-gate/usr/src/cmd/bnu/callers.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
524da5b34Srie  * Common Development and Distribution License (the "License").
624da5b34Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2224da5b34Srie  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "uucp.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4)
327c478bd9Sstevel@tonic-gate #include <netdb.h>
337c478bd9Sstevel@tonic-gate #include <netinet/in.h>
347c478bd9Sstevel@tonic-gate #include <sys/socket.h>
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate #ifdef UNET
377c478bd9Sstevel@tonic-gate #include  "UNET/unetio.h"
387c478bd9Sstevel@tonic-gate #include  "UNET/tcp.h"
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
4124da5b34Srie #include <libgen.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate EXTERN void alarmtr();
447c478bd9Sstevel@tonic-gate EXTERN jmp_buf Sjbuf;
4524da5b34Srie EXTERN char *fdig();
467c478bd9Sstevel@tonic-gate EXTERN int interface();
477c478bd9Sstevel@tonic-gate EXTERN int fd_mklock(), fd_cklock(), chat(), getdialline();
487c478bd9Sstevel@tonic-gate EXTERN void fixline(), fd_rmlock();
497c478bd9Sstevel@tonic-gate static void translate();
507c478bd9Sstevel@tonic-gate static int gdial();
517c478bd9Sstevel@tonic-gate EXTERN int	Modemctrl;
527c478bd9Sstevel@tonic-gate EXTERN unsigned connecttime;
537c478bd9Sstevel@tonic-gate EXTERN int (*Setup)();
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  *	to add a new caller:
577c478bd9Sstevel@tonic-gate  *	declare the function that knows how to call on the device,
587c478bd9Sstevel@tonic-gate  *	add a line to the callers table giving the name of the device
597c478bd9Sstevel@tonic-gate  *	(from Devices file) and the name of the function
607c478bd9Sstevel@tonic-gate  *	add the function to the end of this file
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #ifdef DIAL801
647c478bd9Sstevel@tonic-gate EXTERN int	dial801();
657c478bd9Sstevel@tonic-gate EXTERN int	open801();
667c478bd9Sstevel@tonic-gate #endif
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifdef DATAKIT
697c478bd9Sstevel@tonic-gate EXTERN int	dkcall();
707c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #ifdef V8
737c478bd9Sstevel@tonic-gate int	Dialout();
747c478bd9Sstevel@tonic-gate #endif
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #ifdef TCP
777c478bd9Sstevel@tonic-gate int	unetcall();
787c478bd9Sstevel@tonic-gate int	tcpcall();
797c478bd9Sstevel@tonic-gate #endif /* TCP */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #ifdef SYTEK
827c478bd9Sstevel@tonic-gate int	sytcall();
837c478bd9Sstevel@tonic-gate #endif /* SYTEK */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #ifdef TLI
867c478bd9Sstevel@tonic-gate EXTERN int	tlicall();
877c478bd9Sstevel@tonic-gate #endif /* TLI */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate static struct caller Caller[] = {
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #ifdef DIAL801
927c478bd9Sstevel@tonic-gate 	{"801",		dial801},
937c478bd9Sstevel@tonic-gate 	{"212",		dial801},
947c478bd9Sstevel@tonic-gate #endif /* DIAL801 */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #ifdef V8
977c478bd9Sstevel@tonic-gate 	{"Dialout",	Dialout},	/* ditto but using dialout(III) */
987c478bd9Sstevel@tonic-gate #endif
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #ifdef TCP
1017c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4)
1027c478bd9Sstevel@tonic-gate 	{"TCP",		tcpcall},	/* 4.2BSD sockets */
1037c478bd9Sstevel@tonic-gate #else /* !BSD4_2 */
1047c478bd9Sstevel@tonic-gate #ifdef UNET
1057c478bd9Sstevel@tonic-gate 	{"TCP",		unetcall},	/* 3com implementation of tcp */
1067c478bd9Sstevel@tonic-gate 	{"Unetserver",	unetcall},
1077c478bd9Sstevel@tonic-gate #endif /* UNET */
1087c478bd9Sstevel@tonic-gate #endif /* BSD4_2 || ATTSVR4 */
1097c478bd9Sstevel@tonic-gate #endif /* TCP */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #ifdef DATAKIT
1127c478bd9Sstevel@tonic-gate 	{"DK",		dkcall},	/* standard AT&T DATAKIT VCS caller */
1137c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate #ifdef SYTEK
1167c478bd9Sstevel@tonic-gate 	{"Sytek",	sytcall},	/* untested but should work */
1177c478bd9Sstevel@tonic-gate #endif /* SYTEK */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #ifdef TLI
1207c478bd9Sstevel@tonic-gate 	{"TLI",		tlicall},	/* AT&T Transport Layer Interface */
1217c478bd9Sstevel@tonic-gate #ifdef TLIS
1227c478bd9Sstevel@tonic-gate 	{"TLIS",	tlicall},	/* AT&T Transport Layer Interface */
1237c478bd9Sstevel@tonic-gate #endif /*  TLIS  */
1247c478bd9Sstevel@tonic-gate #endif /* TLI */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	{NULL, 		NULL}		/* this line must be last */
1277c478bd9Sstevel@tonic-gate };
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  *	exphone - expand phone number for given prefix and number
1317c478bd9Sstevel@tonic-gate  *
1327c478bd9Sstevel@tonic-gate  *	return code - none
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate static void
exphone(in,out)1367c478bd9Sstevel@tonic-gate exphone(in, out)
1377c478bd9Sstevel@tonic-gate char *in, *out;
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate 	FILE *fn;
1407c478bd9Sstevel@tonic-gate 	char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH];
1417c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
1427c478bd9Sstevel@tonic-gate 	char *s1;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	if (!isalpha(*in)) {
1457c478bd9Sstevel@tonic-gate 		(void) strcpy(out, in);
1467c478bd9Sstevel@tonic-gate 		return;
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	s1=pre;
1507c478bd9Sstevel@tonic-gate 	while (isalpha(*in))
1517c478bd9Sstevel@tonic-gate 		*s1++ = *in++;
1527c478bd9Sstevel@tonic-gate 	*s1 = NULLCHAR;
1537c478bd9Sstevel@tonic-gate 	s1 = npart;
1547c478bd9Sstevel@tonic-gate 	while (*in != NULLCHAR)
1557c478bd9Sstevel@tonic-gate 		*s1++ = *in++;
1567c478bd9Sstevel@tonic-gate 	*s1 = NULLCHAR;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	tpre[0] = NULLCHAR;
1597c478bd9Sstevel@tonic-gate 	fn = fopen(DIALCODES, "r");
1607c478bd9Sstevel@tonic-gate 	if (fn != NULL) {
1617c478bd9Sstevel@tonic-gate 		while (fgets(buf, BUFSIZ, fn)) {
1627c478bd9Sstevel@tonic-gate 			if ( sscanf(buf, "%s%s", p, tpre) < 1)
1637c478bd9Sstevel@tonic-gate 				continue;
1647c478bd9Sstevel@tonic-gate 			if (EQUALS(p, pre))
1657c478bd9Sstevel@tonic-gate 				break;
1667c478bd9Sstevel@tonic-gate 			tpre[0] = NULLCHAR;
1677c478bd9Sstevel@tonic-gate 		}
1687c478bd9Sstevel@tonic-gate 		fclose(fn);
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	(void) strcpy(out, tpre);
1727c478bd9Sstevel@tonic-gate 	(void) strcat(out, npart);
1737c478bd9Sstevel@tonic-gate 	return;
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * repphone - Replace \D and \T sequences in arg with phone
1787c478bd9Sstevel@tonic-gate  * expanding and translating as appropriate.
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate static char *
repphone(arg,phone,trstr)1817c478bd9Sstevel@tonic-gate repphone(arg, phone, trstr)
182462be471Sceastha char *arg, *phone, *trstr;
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	static char pbuf[2*(MAXPH+2)];
185462be471Sceastha 	char *fp, *tp;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	for (tp=pbuf; *arg; arg++) {
1887c478bd9Sstevel@tonic-gate 		if (*arg != '\\') {
1897c478bd9Sstevel@tonic-gate 			*tp++ = *arg;
1907c478bd9Sstevel@tonic-gate 			continue;
1917c478bd9Sstevel@tonic-gate 		} else {
1927c478bd9Sstevel@tonic-gate 			switch (*(arg+1)) {
1937c478bd9Sstevel@tonic-gate 			case 'T':
1947c478bd9Sstevel@tonic-gate 				exphone(phone, tp);
1957c478bd9Sstevel@tonic-gate 				translate(trstr, tp);
1967c478bd9Sstevel@tonic-gate 				for(; *tp; tp++)
1977c478bd9Sstevel@tonic-gate 				    ;
1987c478bd9Sstevel@tonic-gate 				arg++;
1997c478bd9Sstevel@tonic-gate 				break;
2007c478bd9Sstevel@tonic-gate 			case 'D':
2017c478bd9Sstevel@tonic-gate 				for(fp=phone; *tp = *fp++; tp++)
2027c478bd9Sstevel@tonic-gate 				    ;
2037c478bd9Sstevel@tonic-gate 				arg++;
2047c478bd9Sstevel@tonic-gate 				break;
2057c478bd9Sstevel@tonic-gate 			default:
2067c478bd9Sstevel@tonic-gate 				*tp++ = *arg;
2077c478bd9Sstevel@tonic-gate 				break;
2087c478bd9Sstevel@tonic-gate 			}
2097c478bd9Sstevel@tonic-gate 		}
2107c478bd9Sstevel@tonic-gate 	}
2117c478bd9Sstevel@tonic-gate 	*tp = '\0';
2127c478bd9Sstevel@tonic-gate 	return(pbuf);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate static u_int saved_mode;
2167c478bd9Sstevel@tonic-gate static char saved_dcname[20];
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * processdev - Process a line from the Devices file
2207c478bd9Sstevel@tonic-gate  *
2217c478bd9Sstevel@tonic-gate  * return codes:
2227c478bd9Sstevel@tonic-gate  *	file descriptor  -  succeeded
2237c478bd9Sstevel@tonic-gate  *	FAIL  -  failed
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate GLOBAL int
processdev(flds,dev)2267c478bd9Sstevel@tonic-gate processdev(flds, dev)
227462be471Sceastha char *flds[], *dev[];
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	int dcf = -1;
230462be471Sceastha 	struct caller	*ca;
2317c478bd9Sstevel@tonic-gate 	char *args[D_MAX+1], dcname[20];
232462be471Sceastha 	char **sdev;
2337c478bd9Sstevel@tonic-gate 	EXTERN int pop_push();
2347c478bd9Sstevel@tonic-gate 	EXTERN void  setdevcfg();
235462be471Sceastha 	int nullfd;
2367c478bd9Sstevel@tonic-gate 	char *phonecl;			/* clear phone string */
2377c478bd9Sstevel@tonic-gate 	char phoneex[2*(MAXPH+2)];	/* expanded phone string */
2387c478bd9Sstevel@tonic-gate 	EXTERN void ttygenbrk();
2397c478bd9Sstevel@tonic-gate 	struct termio tty_orig;
2407c478bd9Sstevel@tonic-gate 	int ret_orig = -1;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	sdev = dev;
2437c478bd9Sstevel@tonic-gate 	/*	set up default "break" routine	*/
2447c478bd9Sstevel@tonic-gate 	genbrk = ttygenbrk;
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	/*	initialize Devconfig info	*/
2477c478bd9Sstevel@tonic-gate 	DEBUG(5, "processdev: calling setdevcfg(%s, ", Progname);
2487c478bd9Sstevel@tonic-gate 	DEBUG(5, "%s)\n", flds[F_TYPE]);
2497c478bd9Sstevel@tonic-gate 	setdevcfg(Progname, flds[F_TYPE]);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	for (ca = Caller; ca->CA_type != NULL; ca++) {
2527c478bd9Sstevel@tonic-gate 		/* This will find built-in caller functions */
2537c478bd9Sstevel@tonic-gate 		if (EQUALS(ca->CA_type, dev[D_CALLER])) {
2547c478bd9Sstevel@tonic-gate 			DEBUG(5, "Internal caller type %s\n", dev[D_CALLER]);
2557c478bd9Sstevel@tonic-gate 			if (dev[D_ARG] == NULL) {
2567c478bd9Sstevel@tonic-gate 				/* if NULL - assume translate */
2577c478bd9Sstevel@tonic-gate 				dev[D_ARG+1] = NULL;	/* needed for for loop later to mark the end */
2587c478bd9Sstevel@tonic-gate 				dev[D_ARG] = "\\T";
2597c478bd9Sstevel@tonic-gate 			}
2607c478bd9Sstevel@tonic-gate 			dev[D_ARG] = repphone(dev[D_ARG], flds[F_PHONE], "");
2617c478bd9Sstevel@tonic-gate 			if ((dcf = (*(ca->CA_caller))(flds, dev)) < 0)
2627c478bd9Sstevel@tonic-gate 				return(dcf) ;
2637c478bd9Sstevel@tonic-gate 			if ( interface( ca->CA_type ) ) {
2647c478bd9Sstevel@tonic-gate 				DEBUG(5, "interface(%s) failed", ca->CA_type);
2657c478bd9Sstevel@tonic-gate 				Uerror = SS_DEVICE_FAILED;
2667c478bd9Sstevel@tonic-gate 				/*	restore vanilla unix interface	*/
2677c478bd9Sstevel@tonic-gate 				(void)interface("UNIX");
2687c478bd9Sstevel@tonic-gate 				return(FAIL);
2697c478bd9Sstevel@tonic-gate 			}
2707c478bd9Sstevel@tonic-gate 			dev += 2; /* Skip to next CALLER and ARG */
2717c478bd9Sstevel@tonic-gate 			break;
2727c478bd9Sstevel@tonic-gate 		}
2737c478bd9Sstevel@tonic-gate 	}
2747c478bd9Sstevel@tonic-gate 	if (dcf == -1) {
2757c478bd9Sstevel@tonic-gate 		/* Here if not a built-in caller function */
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 		/* We do locking (file and advisory) after open	*/
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		/*
2807c478bd9Sstevel@tonic-gate 		 * Open the line
2817c478bd9Sstevel@tonic-gate 		 */
2827c478bd9Sstevel@tonic-gate 		if ( *dev[D_LINE] != '/' ) {
2837c478bd9Sstevel@tonic-gate 			(void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
2847c478bd9Sstevel@tonic-gate 		} else {
2857c478bd9Sstevel@tonic-gate 			(void) strcpy(dcname, dev[D_LINE] );
2867c478bd9Sstevel@tonic-gate 		}
2877c478bd9Sstevel@tonic-gate 		/* take care of the possible partial open fd */
2887c478bd9Sstevel@tonic-gate 		(void) close(nullfd = open("/", O_RDONLY));
2897c478bd9Sstevel@tonic-gate 		if (setjmp(Sjbuf)) {
2907c478bd9Sstevel@tonic-gate 			(void) close(nullfd);
2917c478bd9Sstevel@tonic-gate 			DEBUG(1, "generic open timeout\n%s", "");
2927c478bd9Sstevel@tonic-gate 			logent("generic open", "TIMEOUT");
2937c478bd9Sstevel@tonic-gate 			Uerror = SS_CANT_ACCESS_DEVICE;
2947c478bd9Sstevel@tonic-gate 			goto bad;
2957c478bd9Sstevel@tonic-gate 		}
2967c478bd9Sstevel@tonic-gate 		(void) signal(SIGALRM, alarmtr);
2977c478bd9Sstevel@tonic-gate 		(void) alarm(10);
2987c478bd9Sstevel@tonic-gate 		if ( Modemctrl ) {
2997c478bd9Sstevel@tonic-gate 			DEBUG(7, "opening with O_NDELAY set\n%s", "");
3007c478bd9Sstevel@tonic-gate 			dcf = open(dcname, (O_RDWR | O_NDELAY) );
3017c478bd9Sstevel@tonic-gate 			saved_mode = O_RDWR | O_NDELAY;
3027c478bd9Sstevel@tonic-gate 		} else {
3037c478bd9Sstevel@tonic-gate 			dcf = open(dcname, O_RDWR );
3047c478bd9Sstevel@tonic-gate 			saved_mode = O_RDWR;
3057c478bd9Sstevel@tonic-gate 		}
3067c478bd9Sstevel@tonic-gate 		strcpy(saved_dcname, dcname);
3077c478bd9Sstevel@tonic-gate 		(void) alarm(0);
3087c478bd9Sstevel@tonic-gate 		if (dcf < 0) {
3097c478bd9Sstevel@tonic-gate 			DEBUG(1, "generic open failed, errno = %d\n", errno);
3107c478bd9Sstevel@tonic-gate 			(void) close(nullfd);
3117c478bd9Sstevel@tonic-gate 			logent("generic open", "FAILED");
3127c478bd9Sstevel@tonic-gate 			Uerror = SS_CANT_ACCESS_DEVICE;
3137c478bd9Sstevel@tonic-gate 			goto bad;
3147c478bd9Sstevel@tonic-gate 		}
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 		/* check locks BEFORE modifying the stream */
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 		if ( fd_mklock(dcf) != SUCCESS ) {
3197c478bd9Sstevel@tonic-gate 			DEBUG(1, "failed to lock device %s\n", dcname);
3207c478bd9Sstevel@tonic-gate 			Uerror = SS_LOCKED_DEVICE;
3217c478bd9Sstevel@tonic-gate 			goto bad;
3227c478bd9Sstevel@tonic-gate 		}
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 		if ( Modemctrl ) {
3257c478bd9Sstevel@tonic-gate 			DEBUG(7, "clear O_NDELAY\n%s", "");
3267c478bd9Sstevel@tonic-gate 			if ( fcntl(dcf, F_SETFL,
3277c478bd9Sstevel@tonic-gate 				(fcntl(dcf, F_GETFL, 0) & ~O_NDELAY)) < 0 ) {
3287c478bd9Sstevel@tonic-gate 				DEBUG( 7, "clear O_NDELAY failed, errno %d\n", errno);
3297c478bd9Sstevel@tonic-gate 				Uerror = SS_DEVICE_FAILED;
3307c478bd9Sstevel@tonic-gate 				goto bad;
3317c478bd9Sstevel@tonic-gate 			}
3327c478bd9Sstevel@tonic-gate 		}
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	if ( (*Setup)( MASTER, &dcf, &dcf ) ) {
3367c478bd9Sstevel@tonic-gate 		/*	any device|system lock files we should remove?	*/
3377c478bd9Sstevel@tonic-gate 		DEBUG(5, "MASTER Setup failed%s", "");
3387c478bd9Sstevel@tonic-gate 		Uerror = SS_DEVICE_FAILED;
3397c478bd9Sstevel@tonic-gate 		goto bad;
3407c478bd9Sstevel@tonic-gate 	}
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	/* configure any requested streams modules */
3437c478bd9Sstevel@tonic-gate 	if ( !pop_push(dcf) ) {
3447c478bd9Sstevel@tonic-gate 		DEBUG(5, "STREAMS module configuration failed%s\n","");
3457c478bd9Sstevel@tonic-gate 		Uerror = SS_DEVICE_FAILED;
3467c478bd9Sstevel@tonic-gate 		goto bad;
3477c478bd9Sstevel@tonic-gate 	}
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	/* save initial state of line in case script fails */
3507c478bd9Sstevel@tonic-gate 	ret_orig = ioctl(dcf, TCGETA, &tty_orig);
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/* use sdev[] since dev[] is incremented for internal callers */
3537c478bd9Sstevel@tonic-gate 	fixline(dcf, atoi(fdig(sdev[D_CLASS])), D_DIRECT);
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 	/*
3567c478bd9Sstevel@tonic-gate 	 * Now loop through the remaining callers and chat
3577c478bd9Sstevel@tonic-gate 	 * according to scripts in dialers file.
3587c478bd9Sstevel@tonic-gate 	 */
3597c478bd9Sstevel@tonic-gate 	for (; dev[D_CALLER] != NULL; dev += 2) {
360462be471Sceastha 		int w;
3617c478bd9Sstevel@tonic-gate 		/*
3627c478bd9Sstevel@tonic-gate 		 * Scan Dialers file to find an entry
3637c478bd9Sstevel@tonic-gate 		 */
3647c478bd9Sstevel@tonic-gate 		if ((w = gdial(dev[D_CALLER], args, D_MAX)) < 1) {
3657c478bd9Sstevel@tonic-gate 			logent("generic call to gdial", "FAILED");
3667c478bd9Sstevel@tonic-gate 			Uerror = SS_CANT_ACCESS_DEVICE;
3677c478bd9Sstevel@tonic-gate 			goto bad;
3687c478bd9Sstevel@tonic-gate 		}
3697c478bd9Sstevel@tonic-gate 		if (w <= 2)	/* do nothing - no chat */
3707c478bd9Sstevel@tonic-gate 			break;
3717c478bd9Sstevel@tonic-gate 		/*
3727c478bd9Sstevel@tonic-gate 		 * Translate the phone number
3737c478bd9Sstevel@tonic-gate 		 */
3747c478bd9Sstevel@tonic-gate 		if (dev[D_ARG] == NULL) {
3757c478bd9Sstevel@tonic-gate 			/* if NULL - assume no translation */
3767c478bd9Sstevel@tonic-gate 			dev[D_ARG+1] = NULL; /* needed for for loop to mark the end */
3777c478bd9Sstevel@tonic-gate 			dev[D_ARG] = "\\D";
3787c478bd9Sstevel@tonic-gate 		}
379*2a8bcb4eSToomas Soome 
3807c478bd9Sstevel@tonic-gate 		phonecl = repphone(dev[D_ARG], flds[F_PHONE], args[1]);
3817c478bd9Sstevel@tonic-gate 		exphone(phonecl, phoneex);
3827c478bd9Sstevel@tonic-gate 		translate(args[1], phoneex);
3837c478bd9Sstevel@tonic-gate 		/*
3847c478bd9Sstevel@tonic-gate 		 * Chat
3857c478bd9Sstevel@tonic-gate 		 */
3867c478bd9Sstevel@tonic-gate 		if (chat(w-2, &args[2], dcf, phonecl, phoneex) != SUCCESS) {
3877c478bd9Sstevel@tonic-gate 			CDEBUG(5, "\nCHAT gdial(%s) FAILED\n", dev[D_CALLER]);
3887c478bd9Sstevel@tonic-gate 			Uerror = SS_CHAT_FAILED;
3897c478bd9Sstevel@tonic-gate 			goto bad;
3907c478bd9Sstevel@tonic-gate 		}
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 	/*
3937c478bd9Sstevel@tonic-gate 	 * Success at last!
3947c478bd9Sstevel@tonic-gate 	 */
3957c478bd9Sstevel@tonic-gate 	strcpy(Dc, sdev[D_LINE]);
3967c478bd9Sstevel@tonic-gate 	return(dcf);
3977c478bd9Sstevel@tonic-gate bad:
3987c478bd9Sstevel@tonic-gate 	if ( dcf >= 0 ) {
3997c478bd9Sstevel@tonic-gate 		/* reset line settings if we got them in the beginning */
4007c478bd9Sstevel@tonic-gate 		if ( ret_orig == 0 )
4017c478bd9Sstevel@tonic-gate 			(void) ioctl(dcf, TCSETAW, &tty_orig);
4027c478bd9Sstevel@tonic-gate 		fd_rmlock(dcf);
4037c478bd9Sstevel@tonic-gate 		(void)close(dcf);
4047c478bd9Sstevel@tonic-gate 	}
4057c478bd9Sstevel@tonic-gate 	/*	restore vanilla unix interface	*/
4067c478bd9Sstevel@tonic-gate 	(void)interface("UNIX");
4077c478bd9Sstevel@tonic-gate 	return(FAIL);
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate  * clear_hup()	clear the hangup state of the given device
4127c478bd9Sstevel@tonic-gate  */
4137c478bd9Sstevel@tonic-gate GLOBAL int
clear_hup(dcf)4147c478bd9Sstevel@tonic-gate clear_hup(dcf)
4157c478bd9Sstevel@tonic-gate int dcf;
4167c478bd9Sstevel@tonic-gate {
4177c478bd9Sstevel@tonic-gate 	int ndcf;
4187c478bd9Sstevel@tonic-gate 	if ((ndcf = open(saved_dcname, saved_mode)) < 0) {
4197c478bd9Sstevel@tonic-gate 		return (FAIL);
4207c478bd9Sstevel@tonic-gate 	}
4217c478bd9Sstevel@tonic-gate 	if (ndcf != dcf) {
4227c478bd9Sstevel@tonic-gate 		close(ndcf);
4237c478bd9Sstevel@tonic-gate 	}
4247c478bd9Sstevel@tonic-gate 	return (SUCCESS);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate /*
4297c478bd9Sstevel@tonic-gate  * translate the pairs of characters present in the first
4307c478bd9Sstevel@tonic-gate  * string whenever the first of the pair appears in the second
4317c478bd9Sstevel@tonic-gate  * string.
4327c478bd9Sstevel@tonic-gate  */
4337c478bd9Sstevel@tonic-gate static void
translate(ttab,str)4347c478bd9Sstevel@tonic-gate translate(ttab, str)
435462be471Sceastha char *ttab, *str;
4367c478bd9Sstevel@tonic-gate {
437462be471Sceastha 	char *s;
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	for(;*ttab && *(ttab+1); ttab += 2)
4407c478bd9Sstevel@tonic-gate 		for(s=str;*s;s++)
4417c478bd9Sstevel@tonic-gate 			if(*ttab == *s)
4427c478bd9Sstevel@tonic-gate 				*s = *(ttab+1);
4437c478bd9Sstevel@tonic-gate 	return;
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate #define MAXLINE	512
4477c478bd9Sstevel@tonic-gate /*
4487c478bd9Sstevel@tonic-gate  * Get the information about the dialer.
4497c478bd9Sstevel@tonic-gate  * gdial(type, arps, narps)
4507c478bd9Sstevel@tonic-gate  *	type	-> type of dialer (e.g., penril)
4517c478bd9Sstevel@tonic-gate  *	arps	-> array of pointers returned by gdial
4527c478bd9Sstevel@tonic-gate  *	narps	-> number of elements in array returned by gdial
4537c478bd9Sstevel@tonic-gate  * Return value:
4547c478bd9Sstevel@tonic-gate  *	-1	-> Can't open DIALERFILE
4557c478bd9Sstevel@tonic-gate  *	0	-> requested type not found
4567c478bd9Sstevel@tonic-gate  *	>0	-> success - number of fields filled in
4577c478bd9Sstevel@tonic-gate  */
4587c478bd9Sstevel@tonic-gate static int
gdial(type,arps,narps)4597c478bd9Sstevel@tonic-gate gdial(type, arps, narps)
460462be471Sceastha char *type, *arps[];
461462be471Sceastha int narps;
4627c478bd9Sstevel@tonic-gate {
4637c478bd9Sstevel@tonic-gate 	static char info[MAXLINE];
464462be471Sceastha 	int na;
4657c478bd9Sstevel@tonic-gate 	EXTERN void dialreset();
4667c478bd9Sstevel@tonic-gate 	EXTERN char * currdial();
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	DEBUG(2, "gdial(%s) called\n", type);
4697c478bd9Sstevel@tonic-gate 	while (getdialline(info, sizeof(info))) {
4707c478bd9Sstevel@tonic-gate 		if ((info[0] == '#') || (info[0] == ' ') ||
4717c478bd9Sstevel@tonic-gate 		    (info[0] == '\t') || (info[0] == '\n'))
4727c478bd9Sstevel@tonic-gate 			continue;
4737c478bd9Sstevel@tonic-gate 		if ((na = getargs(info, arps, narps)) == 0)
4747c478bd9Sstevel@tonic-gate 			continue;
4757c478bd9Sstevel@tonic-gate 		if (EQUALS(arps[0], type)) {
4767c478bd9Sstevel@tonic-gate 		    DEBUG(5, "Trying caller script '%s'", type);
4777c478bd9Sstevel@tonic-gate 		    DEBUG(5, " from '%s'.\n", currdial());
4787c478bd9Sstevel@tonic-gate 		    dialreset();
4797c478bd9Sstevel@tonic-gate 		    bsfix(arps);
4807c478bd9Sstevel@tonic-gate 		    return(na);
4817c478bd9Sstevel@tonic-gate 		}
4827c478bd9Sstevel@tonic-gate 	}
4837c478bd9Sstevel@tonic-gate 	DEBUG(1, "%s not found in Dialers file\n", type);
4847c478bd9Sstevel@tonic-gate 	dialreset();
4857c478bd9Sstevel@tonic-gate 	return(0);
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate #ifdef DATAKIT
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate  *	dkcall(flds, dev)	make a DATAKIT VCS connection
4937c478bd9Sstevel@tonic-gate  *				  DATAKIT VCS is a trademark of AT&T
4947c478bd9Sstevel@tonic-gate  *
4957c478bd9Sstevel@tonic-gate  *	return codes:
4967c478bd9Sstevel@tonic-gate  *		>0 - file number - ok
4977c478bd9Sstevel@tonic-gate  *		FAIL - failed
4987c478bd9Sstevel@tonic-gate  */
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate #include "dk.h"
5017c478bd9Sstevel@tonic-gate EXTERN int dkdial();
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5047c478bd9Sstevel@tonic-gate GLOBAL int
dkcall(flds,dev)5057c478bd9Sstevel@tonic-gate dkcall(flds, dev)
5067c478bd9Sstevel@tonic-gate char *flds[], *dev[];
5077c478bd9Sstevel@tonic-gate {
508462be471Sceastha 	int fd;
5097c478bd9Sstevel@tonic-gate #ifdef V8
5107c478bd9Sstevel@tonic-gate 	extern int cdkp_ld;
5117c478bd9Sstevel@tonic-gate #endif
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	char	dialstring[64];
5147c478bd9Sstevel@tonic-gate 	EXTERN	void dkbreak();
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	strcpy(dialstring, dev[D_ARG]);
5177c478bd9Sstevel@tonic-gate 	DEBUG(4, "dkcall(%s)\n", dialstring);
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate #ifdef V8
5217c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
5227c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
5237c478bd9Sstevel@tonic-gate 		return(FAIL);
5247c478bd9Sstevel@tonic-gate 	}
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
5277c478bd9Sstevel@tonic-gate 	(void) alarm(connecttime);
5287c478bd9Sstevel@tonic-gate 	DEBUG(4, "tdkdial(%s", flds[F_PHONE]);
5297c478bd9Sstevel@tonic-gate 	DEBUG(4, ", %d)\n", atoi(dev[D_CLASS]));
5307c478bd9Sstevel@tonic-gate     	if ((fd = tdkdial(flds[F_PHONE], atoi(dev[D_CLASS]))) >= 0)
5317c478bd9Sstevel@tonic-gate 	    if (dkproto(fd, cdkp_ld) < 0)
5327c478bd9Sstevel@tonic-gate 	       {
5337c478bd9Sstevel@tonic-gate 	    	close(fd);
5347c478bd9Sstevel@tonic-gate 	    	fd = -1;
5357c478bd9Sstevel@tonic-gate 	       }
5367c478bd9Sstevel@tonic-gate 	(void) alarm(0);
5377c478bd9Sstevel@tonic-gate #else
5387c478bd9Sstevel@tonic-gate 	fd = dkdial(dialstring);
5397c478bd9Sstevel@tonic-gate #endif
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 	(void) strcpy(Dc, "DK");
5427c478bd9Sstevel@tonic-gate 	if (fd < 0) {
5437c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
5447c478bd9Sstevel@tonic-gate 		return(FAIL);
5457c478bd9Sstevel@tonic-gate 	}
5467c478bd9Sstevel@tonic-gate 	else {
5477c478bd9Sstevel@tonic-gate 		genbrk = dkbreak;
5487c478bd9Sstevel@tonic-gate 		return(fd);
5497c478bd9Sstevel@tonic-gate 	}
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate #ifdef TCP
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate /*
5577c478bd9Sstevel@tonic-gate  *	tcpcall(flds, dev)	make ethernet/socket connection
5587c478bd9Sstevel@tonic-gate  *
5597c478bd9Sstevel@tonic-gate  *	return codes:
5607c478bd9Sstevel@tonic-gate  *		>0 - file number - ok
5617c478bd9Sstevel@tonic-gate  *		FAIL - failed
5627c478bd9Sstevel@tonic-gate  */
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate #if !(defined(BSD4_2) || defined(ATTSVR4))
5657c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5667c478bd9Sstevel@tonic-gate GLOBAL int
tcpcall(flds,dev)5677c478bd9Sstevel@tonic-gate tcpcall(flds, dev)
5687c478bd9Sstevel@tonic-gate char	*flds[], *dev[];
5697c478bd9Sstevel@tonic-gate {
5707c478bd9Sstevel@tonic-gate 	Uerror = SS_NO_DEVICE;
5717c478bd9Sstevel@tonic-gate 	return(FAIL);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate #else /* BSD4_2 */
5747c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5757c478bd9Sstevel@tonic-gate GLOBAL int
tcpcall(flds,dev)5767c478bd9Sstevel@tonic-gate tcpcall(flds, dev)
5777c478bd9Sstevel@tonic-gate char *flds[], *dev[];
5787c478bd9Sstevel@tonic-gate {
5797c478bd9Sstevel@tonic-gate 	int ret;
5807c478bd9Sstevel@tonic-gate 	short port;
5817c478bd9Sstevel@tonic-gate 	struct servent *sp;
5827c478bd9Sstevel@tonic-gate 	struct hostent *hp;
5837c478bd9Sstevel@tonic-gate 	struct sockaddr_in sin;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	if (EQUALS(flds[F_CLASS], "-")) {
5867c478bd9Sstevel@tonic-gate 		/*
5877c478bd9Sstevel@tonic-gate 		 * Use standard UUCP port number.
5887c478bd9Sstevel@tonic-gate 		 */
5897c478bd9Sstevel@tonic-gate 		sp = getservbyname("uucp", "tcp");
5907c478bd9Sstevel@tonic-gate 		endservent();
5917c478bd9Sstevel@tonic-gate 		ASSERT(sp != NULL, "No uucp service number", 0, 0);
5927c478bd9Sstevel@tonic-gate 		port = sp->s_port;
5937c478bd9Sstevel@tonic-gate 	} else {
5947c478bd9Sstevel@tonic-gate 		/*
5957c478bd9Sstevel@tonic-gate 		 * Systems file specifies a port number.
5967c478bd9Sstevel@tonic-gate 		 */
5977c478bd9Sstevel@tonic-gate 		sp = getservbyname(flds[F_CLASS], "tcp");
5987c478bd9Sstevel@tonic-gate 		endservent();
5997c478bd9Sstevel@tonic-gate 		if (sp == NULL) {
6007c478bd9Sstevel@tonic-gate 			port = htons(atoi(flds[F_CLASS]));
6017c478bd9Sstevel@tonic-gate 			if (port == 0) {
6027c478bd9Sstevel@tonic-gate 				logent("tcpopen", "unknown port number");
6037c478bd9Sstevel@tonic-gate 				Uerror = SS_NO_DEVICE;
6047c478bd9Sstevel@tonic-gate 				return(FAIL);
6057c478bd9Sstevel@tonic-gate 			}
6067c478bd9Sstevel@tonic-gate 		} else
6077c478bd9Sstevel@tonic-gate 			port = sp->s_port;
6087c478bd9Sstevel@tonic-gate 	}
6097c478bd9Sstevel@tonic-gate 	if (EQUALS(flds[F_PHONE], "-")) {
6107c478bd9Sstevel@tonic-gate 		/*
6117c478bd9Sstevel@tonic-gate 		 * Use UUCP name as host name.
6127c478bd9Sstevel@tonic-gate 		 */
6137c478bd9Sstevel@tonic-gate 		hp = gethostbyname(flds[F_NAME]);
6147c478bd9Sstevel@tonic-gate 	} else {
6157c478bd9Sstevel@tonic-gate 		/*
6167c478bd9Sstevel@tonic-gate 		 * Systems file specifies a host name different from the UUCP
6177c478bd9Sstevel@tonic-gate 		 * host name.
6187c478bd9Sstevel@tonic-gate 		 */
6197c478bd9Sstevel@tonic-gate 		hp = gethostbyname(flds[F_PHONE]);
6207c478bd9Sstevel@tonic-gate 	}
6217c478bd9Sstevel@tonic-gate 	endhostent();
6227c478bd9Sstevel@tonic-gate 	if (hp == NULL) {
6237c478bd9Sstevel@tonic-gate 		logent("tcpopen", "no such host");
6247c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
6257c478bd9Sstevel@tonic-gate 		return(FAIL);
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate 	DEBUG(4, "tcpdial host %s, ", hp->h_name);
6287c478bd9Sstevel@tonic-gate 	DEBUG(4, "port %d\n", ntohs(port));
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	ret = socket(AF_INET, SOCK_STREAM, 0);
6317c478bd9Sstevel@tonic-gate 	if (ret < 0) {
632ace1a5f1Sdp 		DEBUG(5, "no socket: %s\n", strerror(errno));
633ace1a5f1Sdp 		logent("no socket", strerror(errno));
6347c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
6357c478bd9Sstevel@tonic-gate 		return(FAIL);
6367c478bd9Sstevel@tonic-gate 	}
6377c478bd9Sstevel@tonic-gate 	sin.sin_family = hp->h_addrtype;
6387c478bd9Sstevel@tonic-gate #ifdef BSD4_2
6397c478bd9Sstevel@tonic-gate 	bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
6407c478bd9Sstevel@tonic-gate #else
6417c478bd9Sstevel@tonic-gate 	memcpy((caddr_t)&sin.sin_addr, hp->h_addr, hp->h_length);
6427c478bd9Sstevel@tonic-gate #endif
6437c478bd9Sstevel@tonic-gate 	sin.sin_port = port;
6447c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
6457c478bd9Sstevel@tonic-gate 		DEBUG(4, "timeout tcpopen\n%s", "");
6467c478bd9Sstevel@tonic-gate 		logent("tcpopen", "TIMEOUT");
6477c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
6487c478bd9Sstevel@tonic-gate 		return(FAIL);
6497c478bd9Sstevel@tonic-gate 	}
6507c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
6517c478bd9Sstevel@tonic-gate 	(void) alarm(connecttime);
6527c478bd9Sstevel@tonic-gate 	DEBUG(7, "family: %d\n", sin.sin_family);
6537c478bd9Sstevel@tonic-gate 	DEBUG(7, "port: %d\n", sin.sin_port);
6547c478bd9Sstevel@tonic-gate 	DEBUG(7, "addr: %08x\n",*((int *) &sin.sin_addr));
6557c478bd9Sstevel@tonic-gate 	if (connect(ret, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
6567c478bd9Sstevel@tonic-gate 		(void) alarm(0);
6577c478bd9Sstevel@tonic-gate 		(void) close(ret);
658ace1a5f1Sdp 		DEBUG(5, "connect failed: %s\n", strerror(errno));
659ace1a5f1Sdp 		logent("connect failed", strerror(errno));
6607c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
6617c478bd9Sstevel@tonic-gate 		return(FAIL);
6627c478bd9Sstevel@tonic-gate 	}
6637c478bd9Sstevel@tonic-gate 	(void) signal(SIGPIPE, SIG_IGN);  /* watch out for broken ipc link...*/
6647c478bd9Sstevel@tonic-gate 	(void) alarm(0);
6657c478bd9Sstevel@tonic-gate 	(void) strcpy(Dc, "IPC");
6667c478bd9Sstevel@tonic-gate 	return(ret);
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate /*
6727c478bd9Sstevel@tonic-gate  *	unetcall(flds, dev)	make ethernet connection
6737c478bd9Sstevel@tonic-gate  *
6747c478bd9Sstevel@tonic-gate  *	return codes:
6757c478bd9Sstevel@tonic-gate  *		>0 - file number - ok
6767c478bd9Sstevel@tonic-gate  *		FAIL - failed
6777c478bd9Sstevel@tonic-gate  */
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate #ifndef UNET
6807c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6817c478bd9Sstevel@tonic-gate GLOBAL int
unetcall(flds,dev)6827c478bd9Sstevel@tonic-gate unetcall(flds, dev)
6837c478bd9Sstevel@tonic-gate char	*flds[], *dev[];
6847c478bd9Sstevel@tonic-gate {
6857c478bd9Sstevel@tonic-gate 	Uerror = SS_NO_DEVICE;
6867c478bd9Sstevel@tonic-gate 	return(FAIL);
6877c478bd9Sstevel@tonic-gate }
6887c478bd9Sstevel@tonic-gate #else /* UNET */
6897c478bd9Sstevel@tonic-gate GLOBAL int
unetcall(flds,dev)6907c478bd9Sstevel@tonic-gate unetcall(flds, dev)
6917c478bd9Sstevel@tonic-gate char *flds[], *dev[];
6927c478bd9Sstevel@tonic-gate {
6937c478bd9Sstevel@tonic-gate 	int ret;
6947c478bd9Sstevel@tonic-gate 	int port;
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	port = atoi(dev[D_ARG]);
6977c478bd9Sstevel@tonic-gate 	DEBUG(4, "unetdial host %s, ", flds[F_PHONE]);
6987c478bd9Sstevel@tonic-gate 	DEBUG(4, "port %d\n", port);
6997c478bd9Sstevel@tonic-gate 	(void) alarm(connecttime);
7007c478bd9Sstevel@tonic-gate 	ret = tcpopen(flds[F_PHONE], port, 0, TO_ACTIVE, "rw");
7017c478bd9Sstevel@tonic-gate 	(void) alarm(0);
7027c478bd9Sstevel@tonic-gate 	endhnent();
7037c478bd9Sstevel@tonic-gate 	if (ret < 0) {
7047c478bd9Sstevel@tonic-gate 		DEBUG(5, "tcpopen failed: errno %d\n", errno);
7057c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
7067c478bd9Sstevel@tonic-gate 		return(FAIL);
7077c478bd9Sstevel@tonic-gate 	}
7087c478bd9Sstevel@tonic-gate 	(void) strcpy(Dc, "UNET");
7097c478bd9Sstevel@tonic-gate 	return(ret);
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate #endif /* UNET */
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate #endif /* TCP */
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate #ifdef SYTEK
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate /*
7187c478bd9Sstevel@tonic-gate  *	sytcall(flds, dev)	make a sytek connection
7197c478bd9Sstevel@tonic-gate  *
7207c478bd9Sstevel@tonic-gate  *	return codes:
7217c478bd9Sstevel@tonic-gate  *		>0 - file number - ok
7227c478bd9Sstevel@tonic-gate  *		FAIL - failed
7237c478bd9Sstevel@tonic-gate  */
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7267c478bd9Sstevel@tonic-gate GLOBAL int
sytcall(flds,dev)7277c478bd9Sstevel@tonic-gate sytcall(flds, dev)
7287c478bd9Sstevel@tonic-gate char *flds[], *dev[];
7297c478bd9Sstevel@tonic-gate {
7307c478bd9Sstevel@tonic-gate 	int dcr, dcr2, nullfd, ret;
7317c478bd9Sstevel@tonic-gate 	char dcname[20], command[BUFSIZ];
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate 	(void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
7347c478bd9Sstevel@tonic-gate 	DEBUG(4, "dc - %s, ", dcname);
7357c478bd9Sstevel@tonic-gate 	dcr = open(dcname, O_WRONLY|O_NDELAY);
7367c478bd9Sstevel@tonic-gate 	if (dcr < 0) {
7377c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
7387c478bd9Sstevel@tonic-gate 		DEBUG(4, "OPEN FAILED %s\n", dcname);
7397c478bd9Sstevel@tonic-gate 		return(FAIL);
7407c478bd9Sstevel@tonic-gate 	}
7417c478bd9Sstevel@tonic-gate 	if ( fd_mklock(dcr) != SUCCESS ) {
7427c478bd9Sstevel@tonic-gate 		(void)close(dcr);
7437c478bd9Sstevel@tonic-gate 		DEBUG(1, "failed to lock device %s\n", dcname);
7447c478bd9Sstevel@tonic-gate 		Uerror = SS_LOCKED_DEVICE;
7457c478bd9Sstevel@tonic-gate 		return(FAIL);
7467c478bd9Sstevel@tonic-gate 	}
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate 	sytfixline(dcr, atoi(fdig(dev[D_CLASS])), D_DIRECT);
7497c478bd9Sstevel@tonic-gate 	(void) sleep(2);
7507c478bd9Sstevel@tonic-gate 	DEBUG(4, "Calling Sytek unit %s\n", dev[D_ARG]);
7517c478bd9Sstevel@tonic-gate 	(void) sprintf(command,"\r\rcall %s\r", dev[D_ARG]);
7527c478bd9Sstevel@tonic-gate 	ret = (*Write)(dcr, command, strlen(command));
7537c478bd9Sstevel@tonic-gate 	(void) sleep(1);
7547c478bd9Sstevel@tonic-gate 	DEBUG(4, "COM1 return = %d\n", ret);
7557c478bd9Sstevel@tonic-gate 	sytfix2line(dcr);
7567c478bd9Sstevel@tonic-gate 	(void) close(nullfd = open("/", O_RDONLY));
7577c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
7587c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
7597c478bd9Sstevel@tonic-gate 		DEBUG(4, "timeout sytek open\n%s", "");
7607c478bd9Sstevel@tonic-gate 		(void) close(nullfd);
7617c478bd9Sstevel@tonic-gate 		(void) close(dcr2);
7627c478bd9Sstevel@tonic-gate 		fd_rmlock(dcr);
7637c478bd9Sstevel@tonic-gate 		(void) close(dcr);
7647c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
7657c478bd9Sstevel@tonic-gate 		return(FAIL);
7667c478bd9Sstevel@tonic-gate 	}
7677c478bd9Sstevel@tonic-gate 	(void) alarm(10);
7687c478bd9Sstevel@tonic-gate 	dcr2 = open(dcname,O_RDWR);
7697c478bd9Sstevel@tonic-gate 	(void) alarm(0);
7707c478bd9Sstevel@tonic-gate 	fd_rmlock(dcr);
7717c478bd9Sstevel@tonic-gate 	(void) close(dcr);
7727c478bd9Sstevel@tonic-gate 	if (dcr2 < 0) {
7737c478bd9Sstevel@tonic-gate 		DEBUG(4, "OPEN 2 FAILED %s\n", dcname);
7747c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
7757c478bd9Sstevel@tonic-gate 		(void) close(nullfd);	/* kernel might think dc2 is open */
7767c478bd9Sstevel@tonic-gate 		return(FAIL);
7777c478bd9Sstevel@tonic-gate 	}
7787c478bd9Sstevel@tonic-gate 	if ( fd_mklock(dcr2) != SUCCESS ) {
7797c478bd9Sstevel@tonic-gate 		(void)close(dcr2);
7807c478bd9Sstevel@tonic-gate 		DEBUG(1, "failed to lock device %s\n", dcname);
7817c478bd9Sstevel@tonic-gate 		Uerror = SS_LOCKED_DEVICE;
7827c478bd9Sstevel@tonic-gate 		return(FAIL);
7837c478bd9Sstevel@tonic-gate 	return(dcr2);
7847c478bd9Sstevel@tonic-gate }
7857c478bd9Sstevel@tonic-gate 
7867c478bd9Sstevel@tonic-gate #endif /* SYTEK */
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate #ifdef DIAL801
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate /*
7917c478bd9Sstevel@tonic-gate  *	dial801(flds, dev)	dial remote machine on 801/801
7927c478bd9Sstevel@tonic-gate  *	char *flds[], *dev[];
7937c478bd9Sstevel@tonic-gate  *
7947c478bd9Sstevel@tonic-gate  *	return codes:
7957c478bd9Sstevel@tonic-gate  *		file descriptor  -  succeeded
7967c478bd9Sstevel@tonic-gate  *		FAIL  -  failed
7977c478bd9Sstevel@tonic-gate  *
7987c478bd9Sstevel@tonic-gate  *	unfortunately, open801() is different for usg and non-usg
7997c478bd9Sstevel@tonic-gate  */
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8027c478bd9Sstevel@tonic-gate GLOBAL int
8037c478bd9Sstevel@tonic-gate dial801(flds, dev)
8047c478bd9Sstevel@tonic-gate char *flds[], *dev[];
8057c478bd9Sstevel@tonic-gate {
8067c478bd9Sstevel@tonic-gate 	char dcname[20], dnname[20], phone[MAXPH+2];
8077c478bd9Sstevel@tonic-gate 	int dcf = -1, speed;
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate 	(void) sprintf(dnname, "/dev/%s", dev[D_CALLDEV]);
8107c478bd9Sstevel@tonic-gate 	(void) sprintf(phone, "%s%s", dev[D_ARG]   , ACULAST);
8117c478bd9Sstevel@tonic-gate 	(void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
8127c478bd9Sstevel@tonic-gate 	CDEBUG(1, "Use Port %s, ", dcname);
8137c478bd9Sstevel@tonic-gate 	DEBUG(4, "acu - %s, ", dnname);
8147c478bd9Sstevel@tonic-gate 	VERBOSE("Trying modem - %s, ", dcname);	/* for cu */
8157c478bd9Sstevel@tonic-gate 	VERBOSE("acu - %s, ", dnname);	/* for cu */
8167c478bd9Sstevel@tonic-gate 	if(getuid()==0 || GRPCHK(getgid())) {
8177c478bd9Sstevel@tonic-gate 		CDEBUG(1, "Phone Number  %s\n", phone);
8187c478bd9Sstevel@tonic-gate 		/* In cu, only give out the phone number to trusted people. */
8197c478bd9Sstevel@tonic-gate 		VERBOSE("calling  %s:  ", phone);	/* for cu */
8207c478bd9Sstevel@tonic-gate 	}
8217c478bd9Sstevel@tonic-gate 	speed = atoi(fdig(dev[D_CLASS]));
8227c478bd9Sstevel@tonic-gate 	dcf = open801(dcname, dnname, phone, speed);
8237c478bd9Sstevel@tonic-gate 	if (dcf >= 0) {
8247c478bd9Sstevel@tonic-gate 	        if ( fd_mklock(dcf) != SUCCESS ) {
8257c478bd9Sstevel@tonic-gate 			(void) close(dcf);
8267c478bd9Sstevel@tonic-gate 			DEBUG(5, "fd_mklock line %s failed\n", dev[D_LINE]);
8277c478bd9Sstevel@tonic-gate 			Uerror = SS_LOCKED_DEVICE;
8287c478bd9Sstevel@tonic-gate 			return(FAIL);
8297c478bd9Sstevel@tonic-gate 		}
8307c478bd9Sstevel@tonic-gate 		fixline(dcf, speed, D_ACU);
8317c478bd9Sstevel@tonic-gate 		(void) strcpy(Dc, dev[D_LINE]);	/* for later unlock() */
8327c478bd9Sstevel@tonic-gate 		VERBOSE("SUCCEEDED\n%s", "");
8337c478bd9Sstevel@tonic-gate 	} else {
8347c478bd9Sstevel@tonic-gate 		VERBOSE("FAILED\n%s", "");
8357c478bd9Sstevel@tonic-gate 	}
8367c478bd9Sstevel@tonic-gate 	return(dcf);
8377c478bd9Sstevel@tonic-gate }
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 
8407c478bd9Sstevel@tonic-gate #ifndef ATTSV
8417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8427c478bd9Sstevel@tonic-gate GLOBAL int
8437c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed)
8447c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone;
8457c478bd9Sstevel@tonic-gate {
8467c478bd9Sstevel@tonic-gate 	int nw, lt, dcf = -1, nullfd, dnf = -1;
8477c478bd9Sstevel@tonic-gate 	pid_t w_ret, pid = -1;
8487c478bd9Sstevel@tonic-gate 	unsigned timelim;
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 	if ((dnf = open(dnname, O_WRONLY)) < 0) {
8517c478bd9Sstevel@tonic-gate 		DEBUG(5, "can't open %s\n", dnname);
8527c478bd9Sstevel@tonic-gate 		Uerror = SS_CANT_ACCESS_DEVICE;
8537c478bd9Sstevel@tonic-gate 		return(FAIL);
8547c478bd9Sstevel@tonic-gate 	}
8557c478bd9Sstevel@tonic-gate 	DEBUG(5, "%s is open\n", dnname);
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	(void) close(nullfd = open("/dev/null", O_RDONLY));/* partial open hack */
8587c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
8597c478bd9Sstevel@tonic-gate 		DEBUG(4, "timeout modem open\n%s", "");
8607c478bd9Sstevel@tonic-gate 		(void) close(nullfd);
8617c478bd9Sstevel@tonic-gate 		(void) close(dcf);
8627c478bd9Sstevel@tonic-gate 		(void) close(dnf);
8637c478bd9Sstevel@tonic-gate 		logent("801 open", "TIMEOUT");
8647c478bd9Sstevel@tonic-gate 		if (pid > 0) {
8657c478bd9Sstevel@tonic-gate 			kill(pid, 9);
8667c478bd9Sstevel@tonic-gate 			wait((int *) 0);
8677c478bd9Sstevel@tonic-gate 		}
8687c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
8697c478bd9Sstevel@tonic-gate 		return(FAIL);
8707c478bd9Sstevel@tonic-gate 	}
8717c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
8727c478bd9Sstevel@tonic-gate 	timelim = 5 * strlen(phone);
8737c478bd9Sstevel@tonic-gate 	(void) alarm(timelim < connecttime ? connecttime : timelim);
8747c478bd9Sstevel@tonic-gate 	if ((pid = fork()) == 0) {
8757c478bd9Sstevel@tonic-gate 		sleep(2);
8767c478bd9Sstevel@tonic-gate 		nw = (*Write)(dnf, phone, lt = strlen(phone));
8777c478bd9Sstevel@tonic-gate 		if (nw != lt) {
8787c478bd9Sstevel@tonic-gate 			DEBUG(4, "ACU write error %d\n", errno);
8797c478bd9Sstevel@tonic-gate 			logent("ACU write", "FAILED");
8807c478bd9Sstevel@tonic-gate 			exit(1);
8817c478bd9Sstevel@tonic-gate 		}
8827c478bd9Sstevel@tonic-gate 		DEBUG(4, "ACU write ok\n%s", "");
8837c478bd9Sstevel@tonic-gate 		exit(0);
8847c478bd9Sstevel@tonic-gate 	}
8857c478bd9Sstevel@tonic-gate 	/*  open line - will return on carrier */
8867c478bd9Sstevel@tonic-gate 	dcf = open(dcname, O_RDWR);
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	DEBUG(4, "dcf is %d\n", dcf);
8897c478bd9Sstevel@tonic-gate 	if (dcf < 0) {	/* handle like a timeout */
8907c478bd9Sstevel@tonic-gate 		(void) alarm(0);
8917c478bd9Sstevel@tonic-gate 		longjmp(Sjbuf, 1);
8927c478bd9Sstevel@tonic-gate 	}
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 	/* modem is open */
8957c478bd9Sstevel@tonic-gate 	while ((w_ret = wait(&lt)) != pid)
8967c478bd9Sstevel@tonic-gate 		if (w_ret == -1 && errno != EINTR) {
8977c478bd9Sstevel@tonic-gate 			DEBUG(4, "Wait failed errno=%d\n", errno);
8987c478bd9Sstevel@tonic-gate 			(void) close(dcf);
8997c478bd9Sstevel@tonic-gate 			(void) close(dnf);
9007c478bd9Sstevel@tonic-gate 			Uerror = SS_DIAL_FAILED;
9017c478bd9Sstevel@tonic-gate 			return(FAIL);
9027c478bd9Sstevel@tonic-gate 		}
9037c478bd9Sstevel@tonic-gate 	(void) alarm(0);
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	(void) close(dnf);	/* no reason to keep the 801 open */
9067c478bd9Sstevel@tonic-gate 	if (lt != 0) {
9077c478bd9Sstevel@tonic-gate 		DEBUG(4, "Fork Stat %o\n", lt);
9087c478bd9Sstevel@tonic-gate 		(void) close(dcf);
9097c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
9107c478bd9Sstevel@tonic-gate 		return(FAIL);
9117c478bd9Sstevel@tonic-gate 	}
9127c478bd9Sstevel@tonic-gate 	return(dcf);
9137c478bd9Sstevel@tonic-gate }
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate #else /* ATTSV */
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate GLOBAL int
9187c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed)
9197c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone;
9207c478bd9Sstevel@tonic-gate {
9217c478bd9Sstevel@tonic-gate 	int nw, lt, dcf = -1, nullfd, dnf = -1, ret;
9227c478bd9Sstevel@tonic-gate 	unsigned timelim;
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 	(void) close(nullfd = open("/", O_RDONLY));	/* partial open hack */
9257c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
9267c478bd9Sstevel@tonic-gate 		DEBUG(4, "DN write %s\n", "timeout");
9277c478bd9Sstevel@tonic-gate 		(void) close(dnf);
9287c478bd9Sstevel@tonic-gate 		(void) close(dcf);
9297c478bd9Sstevel@tonic-gate 		(void) close(nullfd);
9307c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
9317c478bd9Sstevel@tonic-gate 		return(FAIL);
9327c478bd9Sstevel@tonic-gate 	}
9337c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
9347c478bd9Sstevel@tonic-gate 	timelim = 5 * strlen(phone);
9357c478bd9Sstevel@tonic-gate 	(void) alarm(timelim < connecttime ? connecttime : timelim);
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	if ((dnf = open(dnname, O_WRONLY)) < 0 ) {
9387c478bd9Sstevel@tonic-gate 		DEBUG(5, "can't open %s\n", dnname);
9397c478bd9Sstevel@tonic-gate 		Uerror = SS_CANT_ACCESS_DEVICE;
9407c478bd9Sstevel@tonic-gate 		return(FAIL);
9417c478bd9Sstevel@tonic-gate 	}
9427c478bd9Sstevel@tonic-gate 	DEBUG(5, "%s is open\n", dnname);
9437c478bd9Sstevel@tonic-gate 	if ( fd_mklock(dnf) != SUCCESS ) {
9447c478bd9Sstevel@tonic-gate 		(void)close(dnf);
9457c478bd9Sstevel@tonic-gate 		DEBUG(1, "failed to lock device %s\n", dnname);
9467c478bd9Sstevel@tonic-gate 		Uerror = SS_LOCKED_DEVICE;
9477c478bd9Sstevel@tonic-gate 	}
9487c478bd9Sstevel@tonic-gate 	if (  (dcf = open(dcname, O_RDWR | O_NDELAY)) < 0 ) {
9497c478bd9Sstevel@tonic-gate 		DEBUG(5, "can't open %s\n", dcname);
9507c478bd9Sstevel@tonic-gate 		Uerror = SS_CANT_ACCESS_DEVICE;
9517c478bd9Sstevel@tonic-gate 		return(FAIL);
9527c478bd9Sstevel@tonic-gate 	}
9537c478bd9Sstevel@tonic-gate 	if ( fd_mklock(dcf) != SUCCESS ) {
9547c478bd9Sstevel@tonic-gate 		(void)close(dcf);
9557c478bd9Sstevel@tonic-gate 		DEBUG(1, "failed to lock device %s\n", dcname);
9567c478bd9Sstevel@tonic-gate 		Uerror = SS_LOCKED_DEVICE;
9577c478bd9Sstevel@tonic-gate 		return(FAIL);
9587c478bd9Sstevel@tonic-gate 	}
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 	DEBUG(4, "dcf is %d\n", dcf);
9617c478bd9Sstevel@tonic-gate 	fixline(dcf, speed, D_ACU);
9627c478bd9Sstevel@tonic-gate 	nw = (*Write)(dnf, phone, lt = strlen(phone));
9637c478bd9Sstevel@tonic-gate 	if (nw != lt) {
9647c478bd9Sstevel@tonic-gate 		(void) alarm(0);
9657c478bd9Sstevel@tonic-gate 		DEBUG(4, "ACU write error %d\n", errno);
9667c478bd9Sstevel@tonic-gate 		(void) close(dnf);
9677c478bd9Sstevel@tonic-gate 		(void) close(dcf);
9687c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
9697c478bd9Sstevel@tonic-gate 		return(FAIL);
970*2a8bcb4eSToomas Soome 	} else
9717c478bd9Sstevel@tonic-gate 		DEBUG(4, "ACU write ok\n%s", "");
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 	(void) close(dnf);
9747c478bd9Sstevel@tonic-gate 	(void) close(nullfd = open("/", O_RDONLY));	/* partial open hack */
9757c478bd9Sstevel@tonic-gate 	ret = open(dcname, O_RDWR);  /* wait for carrier  */
9767c478bd9Sstevel@tonic-gate 	(void) alarm(0);
9777c478bd9Sstevel@tonic-gate 	(void) close(ret);	/* close 2nd modem open() */
9787c478bd9Sstevel@tonic-gate 	if (ret < 0) {		/* open() interrupted by alarm */
9797c478bd9Sstevel@tonic-gate 		DEBUG(4, "Line open %s\n", "failed");
9807c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
9817c478bd9Sstevel@tonic-gate 		(void) close(nullfd);		/* close partially opened modem */
9827c478bd9Sstevel@tonic-gate 		return(FAIL);
9837c478bd9Sstevel@tonic-gate 	}
9847c478bd9Sstevel@tonic-gate 	(void) fcntl(dcf,F_SETFL, fcntl(dcf, F_GETFL, 0) & ~O_NDELAY);
9857c478bd9Sstevel@tonic-gate 	return(dcf);
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate #endif /* ATTSV */
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate #endif /* DIAL801 */
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate #ifdef V8
9927c478bd9Sstevel@tonic-gate GLOBAL int
9937c478bd9Sstevel@tonic-gate Dialout(flds)
9947c478bd9Sstevel@tonic-gate char *flds[];
9957c478bd9Sstevel@tonic-gate {
9967c478bd9Sstevel@tonic-gate     int fd;
9977c478bd9Sstevel@tonic-gate     char phone[MAXPH+2];
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate     exphone(flds[F_PHONE], phone);
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate     DEBUG(4, "call dialout(%s", phone);
10027c478bd9Sstevel@tonic-gate     DEBUG(4, ", %s)\n", dev[D_CLASS]);
10037c478bd9Sstevel@tonic-gate     fd = dialout(phone, dev[D_CLASS]);
10047c478bd9Sstevel@tonic-gate     if (fd == -1)
10057c478bd9Sstevel@tonic-gate 	Uerror = SS_NO_DEVICE;
10067c478bd9Sstevel@tonic-gate     if (fd == -3)
10077c478bd9Sstevel@tonic-gate 	Uerror = SS_DIAL_FAILED;
10087c478bd9Sstevel@tonic-gate     if (fd == -9)
10097c478bd9Sstevel@tonic-gate 	Uerror = SS_DEVICE_FAILED;
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate     (void) strcpy(Dc, "Dialout");
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate     return(fd);
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate #endif /* V8 */
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate #ifdef TLI
10187c478bd9Sstevel@tonic-gate /*
10197c478bd9Sstevel@tonic-gate  *
10207c478bd9Sstevel@tonic-gate  * AT&T Transport Layer Interface
10217c478bd9Sstevel@tonic-gate  *
10227c478bd9Sstevel@tonic-gate  * expected in Devices
1023*2a8bcb4eSToomas Soome  *	TLI line1 - - TLI
10247c478bd9Sstevel@tonic-gate  * or
10257c478bd9Sstevel@tonic-gate  *	TLIS line1 - - TLIS
10267c478bd9Sstevel@tonic-gate  *
10277c478bd9Sstevel@tonic-gate  */
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate EXTERN void tfaillog();
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate char *t_alloc();
10347c478bd9Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis();
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate #define	CONNECT_ATTEMPTS	3
10377c478bd9Sstevel@tonic-gate #define	TFREE(p, type)	if ((p)) t_free((char *)(p), (type))
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate /*
10407c478bd9Sstevel@tonic-gate  * returns fd to remote uucp daemon
10417c478bd9Sstevel@tonic-gate  */
10427c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10437c478bd9Sstevel@tonic-gate GLOBAL int
10447c478bd9Sstevel@tonic-gate tlicall(flds, dev)
10457c478bd9Sstevel@tonic-gate char *flds[];
10467c478bd9Sstevel@tonic-gate char *dev[];
10477c478bd9Sstevel@tonic-gate {
10487c478bd9Sstevel@tonic-gate 	char		addrbuf[ BUFSIZ ];
10497c478bd9Sstevel@tonic-gate 	char		devname[MAXNAMESIZE];
10507c478bd9Sstevel@tonic-gate 	int		fd;
1051462be471Sceastha 	int	i, j;
10527c478bd9Sstevel@tonic-gate 	struct t_bind	*bind_ret = 0;
10537c478bd9Sstevel@tonic-gate 	struct t_info	tinfo;
10547c478bd9Sstevel@tonic-gate 	struct t_call	*sndcall = 0, *rcvcall = 0;
10557c478bd9Sstevel@tonic-gate 	extern int	t_errno;
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate 	EXTERN struct netbuf	*stoa();
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 	if ( dev[D_LINE][0] != '/' ) {
10607c478bd9Sstevel@tonic-gate 		/*	dev holds device name relative to /dev	*/
10617c478bd9Sstevel@tonic-gate 		sprintf(devname, "/dev/%s", dev[D_LINE]);
10627c478bd9Sstevel@tonic-gate 	} else {
10637c478bd9Sstevel@tonic-gate 		/*	dev holds full path name of device	*/
10647c478bd9Sstevel@tonic-gate 		strcpy(devname, dev[D_LINE]);
10657c478bd9Sstevel@tonic-gate 	}
10667c478bd9Sstevel@tonic-gate 	/* gimme local transport endpoint */
10677c478bd9Sstevel@tonic-gate 	errno = t_errno = 0;
10687c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
10697c478bd9Sstevel@tonic-gate 		DEBUG(1, "t_open timeout\n%s", "");
10707c478bd9Sstevel@tonic-gate 		logent("t_open", "TIMEOUT");
10717c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
10727c478bd9Sstevel@tonic-gate 		return(FAIL);
10737c478bd9Sstevel@tonic-gate 	}
10747c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
10757c478bd9Sstevel@tonic-gate 	(void) alarm(5);
10767c478bd9Sstevel@tonic-gate 	fd = t_open(devname, O_RDWR, &tinfo);
10777c478bd9Sstevel@tonic-gate 	(void) alarm(0);
10787c478bd9Sstevel@tonic-gate 	if (fd < 0) {
10797c478bd9Sstevel@tonic-gate 		tfaillog(fd, "t_open" );
10807c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
10817c478bd9Sstevel@tonic-gate 		return(FAIL);
10827c478bd9Sstevel@tonic-gate 	}
10837c478bd9Sstevel@tonic-gate 	if ( fd_mklock(fd) != SUCCESS ) {
10847c478bd9Sstevel@tonic-gate 		(void)t_close(fd);
10857c478bd9Sstevel@tonic-gate 		DEBUG(1, "tlicall: failed to lock device %s\n", devname);
10867c478bd9Sstevel@tonic-gate 		Uerror = SS_LOCKED_DEVICE;
10877c478bd9Sstevel@tonic-gate 		return(FAIL);
10887c478bd9Sstevel@tonic-gate 	}
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate 	/* allocate tli structures	*/
10917c478bd9Sstevel@tonic-gate 	errno = t_errno = 0;
1092*2a8bcb4eSToomas Soome 	if ( (bind_ret = (struct t_bind *)t_alloc(fd, T_BIND, T_ALL)) ==
10937c478bd9Sstevel@tonic-gate 	    (struct t_bind *)NULL
1094*2a8bcb4eSToomas Soome 	|| (sndcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) ==
10957c478bd9Sstevel@tonic-gate 	    (struct t_call *)NULL
10967c478bd9Sstevel@tonic-gate 	|| (rcvcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) ==
10977c478bd9Sstevel@tonic-gate 	    (struct t_call *)NULL ) {
10987c478bd9Sstevel@tonic-gate 		tfaillog(fd, "t_alloc" );
10997c478bd9Sstevel@tonic-gate 		TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11007c478bd9Sstevel@tonic-gate 		TFREE(rcvcall, T_CALL);
11017c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
11027c478bd9Sstevel@tonic-gate 		return(FAIL);
11037c478bd9Sstevel@tonic-gate 	}
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 	/* bind */
11067c478bd9Sstevel@tonic-gate 	errno = t_errno = 0;
11077c478bd9Sstevel@tonic-gate 	if (t_bind(fd, (struct t_bind *) 0, bind_ret ) < 0) {
11087c478bd9Sstevel@tonic-gate 		tfaillog(fd, "t_bind" );
11097c478bd9Sstevel@tonic-gate 		TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11107c478bd9Sstevel@tonic-gate 		TFREE(rcvcall, T_CALL);
11117c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
11127c478bd9Sstevel@tonic-gate 		fd_rmlock(fd);
11137c478bd9Sstevel@tonic-gate 		(void) t_close(fd);
11147c478bd9Sstevel@tonic-gate 		return(FAIL);
11157c478bd9Sstevel@tonic-gate 	}
11167c478bd9Sstevel@tonic-gate 	DEBUG(5, "tlicall: bound to %s\n", bind_ret->addr.buf);
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 	/*
11197c478bd9Sstevel@tonic-gate 	 * Prepare to connect.
11207c478bd9Sstevel@tonic-gate 	 *
11217c478bd9Sstevel@tonic-gate 	 * If address begins with "\x", "\X", "\o", or "\O",
11227c478bd9Sstevel@tonic-gate 	 * assume is hexadecimal or octal address and use stoa()
11237c478bd9Sstevel@tonic-gate 	 * to convert it.
11247c478bd9Sstevel@tonic-gate 	 *
11257c478bd9Sstevel@tonic-gate 	 * Else is usual uucico address -- only \N's left to process.
11267c478bd9Sstevel@tonic-gate 	 * Walk thru connection address, changing \N's to NULLCHARs.
11277c478bd9Sstevel@tonic-gate 	 * Note:  If a NULLCHAR must be part of the connection address,
11287c478bd9Sstevel@tonic-gate 	 * it must be overtly included in the address.  One recommended
11297c478bd9Sstevel@tonic-gate 	 * way is to do it in the Devices file, thusly:
11307c478bd9Sstevel@tonic-gate 	 *		Netname /dev/netport - - TLI \D\000
11317c478bd9Sstevel@tonic-gate 	 * bsfix() turns \000 into \N and then the loop below makes it a
11327c478bd9Sstevel@tonic-gate 	 * real, included-in-the-length null-byte.
11337c478bd9Sstevel@tonic-gate 	 *
11347c478bd9Sstevel@tonic-gate 	 * The DEBUG must print the strecpy'd address (so that
11357c478bd9Sstevel@tonic-gate 	 * non-printables will have been replaced with C escapes).
11367c478bd9Sstevel@tonic-gate 	 */
11377c478bd9Sstevel@tonic-gate 
11387c478bd9Sstevel@tonic-gate 	DEBUG(5, "t_connect to addr \"%s\"\n",
11397c478bd9Sstevel@tonic-gate 		strecpy( addrbuf, dev[D_ARG], "\\" ) );
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate 	if ( dev[D_ARG][0] == '\\' &&
11427c478bd9Sstevel@tonic-gate 	( dev[D_ARG][1] == 'x' || dev[D_ARG][1] == 'X'
11437c478bd9Sstevel@tonic-gate 	|| dev[D_ARG][1] == 'o' || dev[D_ARG][1] == 'O' ) ) {
11447c478bd9Sstevel@tonic-gate 		if ( stoa(dev[D_ARG], &(sndcall->addr)) == (struct netbuf *)NULL ) {
11457c478bd9Sstevel@tonic-gate 			DEBUG(5, "tlicall: stoa failed\n%s", "");
11467c478bd9Sstevel@tonic-gate 			logent("tlicall", "string-to-address failed");
11477c478bd9Sstevel@tonic-gate 			TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11487c478bd9Sstevel@tonic-gate 			TFREE(rcvcall, T_CALL);
11497c478bd9Sstevel@tonic-gate 			Uerror = SS_NO_DEVICE;
11507c478bd9Sstevel@tonic-gate 			fd_rmlock(fd);
11517c478bd9Sstevel@tonic-gate 			(void) t_close(fd);
11527c478bd9Sstevel@tonic-gate 			return(FAIL);
11537c478bd9Sstevel@tonic-gate 		}
11547c478bd9Sstevel@tonic-gate 	} else {
11557c478bd9Sstevel@tonic-gate 		for( i = j = 0; i < BUFSIZ && dev[D_ARG][i] != NULLCHAR;
11567c478bd9Sstevel@tonic-gate 		++i, ++j ) {
11577c478bd9Sstevel@tonic-gate 			if( dev[D_ARG][i] == '\\'  &&  dev[D_ARG][i+1] == 'N' ) {
11587c478bd9Sstevel@tonic-gate 				addrbuf[j] = NULLCHAR;
11597c478bd9Sstevel@tonic-gate 				++i;
11607c478bd9Sstevel@tonic-gate 			}
11617c478bd9Sstevel@tonic-gate 			else {
11627c478bd9Sstevel@tonic-gate 				addrbuf[j] = dev[D_ARG][i];
11637c478bd9Sstevel@tonic-gate 			}
11647c478bd9Sstevel@tonic-gate 		}
11657c478bd9Sstevel@tonic-gate 		sndcall->addr.buf = addrbuf;
11667c478bd9Sstevel@tonic-gate 		sndcall->addr.len = j;
11677c478bd9Sstevel@tonic-gate 	}
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
11707c478bd9Sstevel@tonic-gate 		DEBUG(4, "timeout tlicall\n%s", "");
11717c478bd9Sstevel@tonic-gate 		logent("tlicall", "TIMEOUT");
11727c478bd9Sstevel@tonic-gate 		TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11737c478bd9Sstevel@tonic-gate 		TFREE(rcvcall, T_CALL);
11747c478bd9Sstevel@tonic-gate 		Uerror = SS_NO_DEVICE;
11757c478bd9Sstevel@tonic-gate 		fd_rmlock(fd);
11767c478bd9Sstevel@tonic-gate 		(void) t_close(fd);
11777c478bd9Sstevel@tonic-gate 		return(FAIL);
11787c478bd9Sstevel@tonic-gate 	}
11797c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
11807c478bd9Sstevel@tonic-gate 	(void) alarm(connecttime);
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 	/* connect to the service -- some listeners can't handle */
11837c478bd9Sstevel@tonic-gate 	/* multiple connect requests, so try it a few times */
11847c478bd9Sstevel@tonic-gate 	errno = t_errno = 0;
11857c478bd9Sstevel@tonic-gate 	for ( i = 0; i < CONNECT_ATTEMPTS; ++i ) {
11867c478bd9Sstevel@tonic-gate 		if (t_connect(fd, sndcall, rcvcall) == 0)
11877c478bd9Sstevel@tonic-gate 			break;
11887c478bd9Sstevel@tonic-gate 		if ( (t_errno == TLOOK) && (t_look(fd) == T_DISCONNECT)) {
11897c478bd9Sstevel@tonic-gate 			t_rcvdis(fd,NULL);
11907c478bd9Sstevel@tonic-gate 			(void) alarm(0);
11917c478bd9Sstevel@tonic-gate 		} else {
11927c478bd9Sstevel@tonic-gate 			(void) alarm(0);
11937c478bd9Sstevel@tonic-gate 			tfaillog(fd, "t_connect");
11947c478bd9Sstevel@tonic-gate 			TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11957c478bd9Sstevel@tonic-gate 			TFREE(rcvcall, T_CALL);
11967c478bd9Sstevel@tonic-gate 			Uerror = SS_DIAL_FAILED;
11977c478bd9Sstevel@tonic-gate 			fd_rmlock(fd);
11987c478bd9Sstevel@tonic-gate 			(void) t_close(fd);
11997c478bd9Sstevel@tonic-gate 			return(FAIL);
12007c478bd9Sstevel@tonic-gate 		}
12017c478bd9Sstevel@tonic-gate 	}
12027c478bd9Sstevel@tonic-gate 	(void) alarm(0);
12037c478bd9Sstevel@tonic-gate 	TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
12047c478bd9Sstevel@tonic-gate 	TFREE(rcvcall, T_CALL);
12057c478bd9Sstevel@tonic-gate 	if ( i == CONNECT_ATTEMPTS ) {
12067c478bd9Sstevel@tonic-gate 		tfaillog(fd, "t_connect");
12077c478bd9Sstevel@tonic-gate 		Uerror = SS_DIAL_FAILED;
12087c478bd9Sstevel@tonic-gate 		fd_rmlock(fd);
12097c478bd9Sstevel@tonic-gate 		(void) t_close(fd);
12107c478bd9Sstevel@tonic-gate 		return(FAIL);
12117c478bd9Sstevel@tonic-gate 	}
12127c478bd9Sstevel@tonic-gate 	errno = t_errno = 0;
12137c478bd9Sstevel@tonic-gate 	(void) strcpy(Dc, dev[D_CALLER]);
12147c478bd9Sstevel@tonic-gate 	return(fd);
12157c478bd9Sstevel@tonic-gate }
12167c478bd9Sstevel@tonic-gate #endif /* TLI */
1217