Annotation of src/usr.bin/tip/cu.c, Revision 1.17
1.17 ! deraadt 1: /* $OpenBSD: cu.c,v 1.16 2004/11/07 09:48:08 otto 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.17 ! deraadt 37: static const char rcsid[] = "$OpenBSD: cu.c,v 1.16 2004/11/07 09:48:08 otto 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.17 ! deraadt 49: cumain(int argc, char *argv[])
1.1 deraadt 50: {
1.11 miod 51: int ch, i, parity;
1.6 millert 52: long l;
53: char *cp;
1.1 deraadt 54: static char sbuf[12];
55:
1.6 millert 56: if (argc < 2)
57: cuusage();
1.1 deraadt 58: CU = DV = NOSTR;
59: BR = DEFBR;
1.11 miod 60: parity = 0; /* none */
1.6 millert 61: while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
1.17 ! deraadt 62: switch (ch) {
1.1 deraadt 63: case 'a':
1.6 millert 64: CU = optarg;
65: break;
66: case 'l':
1.8 deraadt 67: if (DV != NULL) {
68: fprintf(stderr,
69: "%s: cannot specificy multiple -l options\n",
70: __progname);
71: exit(3);
72: }
73: if (strchr(optarg, '/'))
74: DV = optarg;
75: else
76: asprintf(&DV, "/dev/%s", optarg);
1.1 deraadt 77: break;
78: case 's':
1.6 millert 79: l = strtol(optarg, &cp, 10);
1.13 millert 80: if (*cp != '\0' || l < 0 || l >= INT_MAX) {
1.6 millert 81: fprintf(stderr, "%s: unsupported speed %s\n",
82: __progname, optarg);
1.1 deraadt 83: exit(3);
84: }
1.6 millert 85: BR = (int)l;
86: break;
87: case 'h':
1.9 millert 88: setboolean(value(LECHO), TRUE);
1.6 millert 89: HD = TRUE;
90: break;
91: case 't':
92: HW = 1, DU = -1;
1.1 deraadt 93: break;
1.6 millert 94: case 'o':
1.11 miod 95: if (parity != 0)
96: parity = 0; /* -e -o */
97: else
98: parity = 1; /* odd */
1.6 millert 99: break;
100: case 'e':
1.11 miod 101: if (parity != 0)
102: parity = 0; /* -o -e */
103: else
104: parity = -1; /* even */
1.1 deraadt 105: break;
106: case '0': case '1': case '2': case '3': case '4':
107: case '5': case '6': case '7': case '8': case '9':
108: if (CU)
1.6 millert 109: CU[strlen(CU)-1] = ch;
1.1 deraadt 110: if (DV)
1.6 millert 111: DV[strlen(DV)-1] = ch;
1.1 deraadt 112: break;
113: default:
1.10 pvalchev 114: cuusage();
1.1 deraadt 115: break;
116: }
117: }
1.6 millert 118: argc -= optind;
119: argv += optind;
120:
121: switch (argc) {
122: case 1:
123: PN = argv[0];
124: break;
125: case 0:
126: break;
127: default:
128: cuusage();
129: break;
130: }
131:
1.1 deraadt 132: signal(SIGINT, cleanup);
133: signal(SIGQUIT, cleanup);
134: signal(SIGHUP, cleanup);
135: signal(SIGTERM, cleanup);
1.16 otto 136: signal(SIGCHLD, SIG_DFL);
1.1 deraadt 137:
138: /*
139: * The "cu" host name is used to define the
140: * attributes of the generic dialer.
141: */
1.4 deraadt 142: (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
1.1 deraadt 143: if ((i = hunt(sbuf)) == 0) {
144: printf("all ports busy\n");
145: exit(3);
146: }
147: if (i == -1) {
148: printf("link down\n");
149: (void)uu_unlock(uucplock);
150: exit(3);
151: }
152: setbuf(stdout, NULL);
153: loginit();
154: user_uid();
155: vinit();
1.11 miod 156: switch (parity) {
157: case -1:
158: setparity("even");
159: break;
160: case 1:
161: setparity("odd");
162: break;
163: default:
164: setparity("none");
165: break;
166: }
1.9 millert 167: setboolean(value(VERBOSE), FALSE);
1.13 millert 168: if (HW && ttysetup(BR)) {
169: fprintf(stderr, "%s: unsupported speed %ld\n",
170: __progname, BR);
171: daemon_uid();
172: (void)uu_unlock(uucplock);
173: exit(3);
174: }
1.17 ! deraadt 175: if (con()) {
1.1 deraadt 176: printf("Connect failed\n");
177: daemon_uid();
178: (void)uu_unlock(uucplock);
179: exit(1);
180: }
1.13 millert 181: if (!HW && ttysetup(BR)) {
182: fprintf(stderr, "%s: unsupported speed %ld\n",
183: __progname, BR);
184: daemon_uid();
185: (void)uu_unlock(uucplock);
186: exit(3);
187: }
1.6 millert 188: }
189:
190: void
1.17 ! deraadt 191: cuusage(void)
1.6 millert 192: {
193: fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] "
194: "[phone-number]\n");
195: exit(8);
1.1 deraadt 196: }