Annotation of src/usr.bin/tip/cu.c, Revision 1.12
1.12 ! hugh 1: /* $OpenBSD: cu.c,v 1.11 2002/02/10 23:22:10 miod Exp $ */
1.3 millert 2: /* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1983, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
40: #endif
1.12 ! hugh 41: static const char rcsid[] = "$OpenBSD: cu.c,v 1.11 2002/02/10 23:22:10 miod Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include "tip.h"
45:
46: void cleanup();
1.6 millert 47: void cuusage();
1.1 deraadt 48:
49: /*
50: * Botch the interface to look like cu's
51: */
1.4 deraadt 52: void
1.1 deraadt 53: cumain(argc, argv)
1.4 deraadt 54: int argc;
1.1 deraadt 55: char *argv[];
56: {
1.11 miod 57: int ch, i, parity;
1.6 millert 58: long l;
59: char *cp;
1.1 deraadt 60: static char sbuf[12];
61:
1.6 millert 62: if (argc < 2)
63: cuusage();
1.1 deraadt 64: CU = DV = NOSTR;
65: BR = DEFBR;
1.11 miod 66: parity = 0; /* none */
1.6 millert 67: while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
68: switch(ch) {
1.1 deraadt 69: case 'a':
1.6 millert 70: CU = optarg;
71: break;
72: case 'l':
1.8 deraadt 73: if (DV != NULL) {
74: fprintf(stderr,
75: "%s: cannot specificy multiple -l options\n",
76: __progname);
77: exit(3);
78: }
79: if (strchr(optarg, '/'))
80: DV = optarg;
81: else
82: asprintf(&DV, "/dev/%s", optarg);
1.1 deraadt 83: break;
84: case 's':
1.6 millert 85: l = strtol(optarg, &cp, 10);
86: if (*cp != '\0' || l < 0 || l >= INT_MAX ||
87: speed((int)l) == 0) {
88: fprintf(stderr, "%s: unsupported speed %s\n",
89: __progname, optarg);
1.1 deraadt 90: exit(3);
91: }
1.6 millert 92: BR = (int)l;
93: break;
94: case 'h':
1.9 millert 95: setboolean(value(LECHO), TRUE);
1.6 millert 96: HD = TRUE;
97: break;
98: case 't':
99: HW = 1, DU = -1;
1.1 deraadt 100: break;
1.6 millert 101: case 'o':
1.11 miod 102: if (parity != 0)
103: parity = 0; /* -e -o */
104: else
105: parity = 1; /* odd */
1.6 millert 106: break;
107: case 'e':
1.11 miod 108: if (parity != 0)
109: parity = 0; /* -o -e */
110: else
111: parity = -1; /* even */
1.1 deraadt 112: break;
113: case '0': case '1': case '2': case '3': case '4':
114: case '5': case '6': case '7': case '8': case '9':
115: if (CU)
1.6 millert 116: CU[strlen(CU)-1] = ch;
1.1 deraadt 117: if (DV)
1.6 millert 118: DV[strlen(DV)-1] = ch;
1.1 deraadt 119: break;
120: default:
1.10 pvalchev 121: cuusage();
1.1 deraadt 122: break;
123: }
124: }
1.6 millert 125: argc -= optind;
126: argv += optind;
127:
128: switch (argc) {
129: case 1:
130: PN = argv[0];
131: break;
132: case 0:
133: break;
134: default:
135: cuusage();
136: break;
137: }
138:
1.1 deraadt 139: signal(SIGINT, cleanup);
140: signal(SIGQUIT, cleanup);
141: signal(SIGHUP, cleanup);
142: signal(SIGTERM, cleanup);
143:
144: /*
145: * The "cu" host name is used to define the
146: * attributes of the generic dialer.
147: */
1.4 deraadt 148: (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
1.1 deraadt 149: if ((i = hunt(sbuf)) == 0) {
150: printf("all ports busy\n");
151: exit(3);
152: }
153: if (i == -1) {
154: printf("link down\n");
155: (void)uu_unlock(uucplock);
156: exit(3);
157: }
158: setbuf(stdout, NULL);
159: loginit();
160: user_uid();
161: vinit();
1.11 miod 162: switch (parity) {
163: case -1:
164: setparity("even");
165: break;
166: case 1:
167: setparity("odd");
168: break;
169: default:
170: setparity("none");
171: break;
172: }
1.9 millert 173: setboolean(value(VERBOSE), FALSE);
1.1 deraadt 174: if (HW)
175: ttysetup(speed(BR));
176: if (connect()) {
177: printf("Connect failed\n");
178: daemon_uid();
179: (void)uu_unlock(uucplock);
180: exit(1);
181: }
182: if (!HW)
183: ttysetup(speed(BR));
1.6 millert 184: }
185:
186: void
187: cuusage()
188: {
189: fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] "
190: "[phone-number]\n");
191: exit(8);
1.1 deraadt 192: }