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