xref: /netbsd-src/usr.bin/tip/cu.c (revision ce0bb6e8d2e560ecacbe865a848624f94498063b)
1 /*	$NetBSD: cu.c,v 1.3 1994/12/08 09:30:48 jtc Exp $	*/
2 
3 /*
4  * Copyright (c) 1983, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)cu.c	8.1 (Berkeley) 6/6/93";
39 #endif
40 static char rcsid[] = "$NetBSD: cu.c,v 1.3 1994/12/08 09:30:48 jtc Exp $";
41 #endif /* not lint */
42 
43 #include "tip.h"
44 
45 void	cleanup();
46 
47 /*
48  * Botch the interface to look like cu's
49  */
50 cumain(argc, argv)
51 	char *argv[];
52 {
53 	register int i;
54 	static char sbuf[12];
55 
56 	if (argc < 2) {
57 		printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
58 		exit(8);
59 	}
60 	CU = DV = NOSTR;
61 	BR = DEFBR;
62 	for (; argc > 1; argv++, argc--) {
63 		if (argv[1][0] != '-')
64 			PN = argv[1];
65 		else switch (argv[1][1]) {
66 
67 		case 't':
68 			HW = 1, DU = -1;
69 			--argc;
70 			continue;
71 
72 		case 'a':
73 			CU = argv[2]; ++argv; --argc;
74 			break;
75 
76 		case 's':
77 			if (argc < 3 || speed(atoi(argv[2])) == 0) {
78 				fprintf(stderr, "cu: unsupported speed %s\n",
79 					argv[2]);
80 				exit(3);
81 			}
82 			BR = atoi(argv[2]); ++argv; --argc;
83 			break;
84 
85 		case 'l':
86 			DV = argv[2]; ++argv; --argc;
87 			break;
88 
89 		case '0': case '1': case '2': case '3': case '4':
90 		case '5': case '6': case '7': case '8': case '9':
91 			if (CU)
92 				CU[strlen(CU)-1] = argv[1][1];
93 			if (DV)
94 				DV[strlen(DV)-1] = argv[1][1];
95 			break;
96 
97 		default:
98 			printf("Bad flag %s", argv[1]);
99 			break;
100 		}
101 	}
102 	signal(SIGINT, cleanup);
103 	signal(SIGQUIT, cleanup);
104 	signal(SIGHUP, cleanup);
105 	signal(SIGTERM, cleanup);
106 
107 	/*
108 	 * The "cu" host name is used to define the
109 	 * attributes of the generic dialer.
110 	 */
111 	(void)sprintf(sbuf, "cu%d", BR);
112 	if ((i = hunt(sbuf)) == 0) {
113 		printf("all ports busy\n");
114 		exit(3);
115 	}
116 	if (i == -1) {
117 		printf("link down\n");
118 		(void)uu_unlock(uucplock);
119 		exit(3);
120 	}
121 	setbuf(stdout, NULL);
122 	loginit();
123 	user_uid();
124 	vinit();
125 	setparity("none");
126 	boolean(value(VERBOSE)) = 0;
127 	if (HW)
128 		ttysetup(speed(BR));
129 	if (connect()) {
130 		printf("Connect failed\n");
131 		daemon_uid();
132 		(void)uu_unlock(uucplock);
133 		exit(1);
134 	}
135 	if (!HW)
136 		ttysetup(speed(BR));
137 }
138