Annotation of src/usr.bin/tip/cu.c, Revision 1.13
1.13 ! millert 1: /* $OpenBSD: cu.c,v 1.12 2002/05/07 06:56:50 hugh 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.13 ! millert 41: static const char rcsid[] = "$OpenBSD: cu.c,v 1.12 2002/05/07 06:56:50 hugh 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);
1.13 ! millert 86: if (*cp != '\0' || l < 0 || l >= INT_MAX) {
1.6 millert 87: fprintf(stderr, "%s: unsupported speed %s\n",
88: __progname, optarg);
1.1 deraadt 89: exit(3);
90: }
1.6 millert 91: BR = (int)l;
92: break;
93: case 'h':
1.9 millert 94: setboolean(value(LECHO), TRUE);
1.6 millert 95: HD = TRUE;
96: break;
97: case 't':
98: HW = 1, DU = -1;
1.1 deraadt 99: break;
1.6 millert 100: case 'o':
1.11 miod 101: if (parity != 0)
102: parity = 0; /* -e -o */
103: else
104: parity = 1; /* odd */
1.6 millert 105: break;
106: case 'e':
1.11 miod 107: if (parity != 0)
108: parity = 0; /* -o -e */
109: else
110: parity = -1; /* even */
1.1 deraadt 111: break;
112: case '0': case '1': case '2': case '3': case '4':
113: case '5': case '6': case '7': case '8': case '9':
114: if (CU)
1.6 millert 115: CU[strlen(CU)-1] = ch;
1.1 deraadt 116: if (DV)
1.6 millert 117: DV[strlen(DV)-1] = ch;
1.1 deraadt 118: break;
119: default:
1.10 pvalchev 120: cuusage();
1.1 deraadt 121: break;
122: }
123: }
1.6 millert 124: argc -= optind;
125: argv += optind;
126:
127: switch (argc) {
128: case 1:
129: PN = argv[0];
130: break;
131: case 0:
132: break;
133: default:
134: cuusage();
135: break;
136: }
137:
1.1 deraadt 138: signal(SIGINT, cleanup);
139: signal(SIGQUIT, cleanup);
140: signal(SIGHUP, cleanup);
141: signal(SIGTERM, cleanup);
142:
143: /*
144: * The "cu" host name is used to define the
145: * attributes of the generic dialer.
146: */
1.4 deraadt 147: (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
1.1 deraadt 148: if ((i = hunt(sbuf)) == 0) {
149: printf("all ports busy\n");
150: exit(3);
151: }
152: if (i == -1) {
153: printf("link down\n");
154: (void)uu_unlock(uucplock);
155: exit(3);
156: }
157: setbuf(stdout, NULL);
158: loginit();
159: user_uid();
160: vinit();
1.11 miod 161: switch (parity) {
162: case -1:
163: setparity("even");
164: break;
165: case 1:
166: setparity("odd");
167: break;
168: default:
169: setparity("none");
170: break;
171: }
1.9 millert 172: setboolean(value(VERBOSE), FALSE);
1.13 ! millert 173: if (HW && ttysetup(BR)) {
! 174: fprintf(stderr, "%s: unsupported speed %ld\n",
! 175: __progname, BR);
! 176: daemon_uid();
! 177: (void)uu_unlock(uucplock);
! 178: exit(3);
! 179: }
1.1 deraadt 180: if (connect()) {
181: printf("Connect failed\n");
182: daemon_uid();
183: (void)uu_unlock(uucplock);
184: exit(1);
185: }
1.13 ! millert 186: if (!HW && ttysetup(BR)) {
! 187: fprintf(stderr, "%s: unsupported speed %ld\n",
! 188: __progname, BR);
! 189: daemon_uid();
! 190: (void)uu_unlock(uucplock);
! 191: exit(3);
! 192: }
1.6 millert 193: }
194:
195: void
196: cuusage()
197: {
198: fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] "
199: "[phone-number]\n");
200: exit(8);
1.1 deraadt 201: }