1 /* $OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $ */
2 /* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
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
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
39 static const char rcsid[] = "$OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $";
45 static void cuusage(void);
48 * Botch the interface to look like cu's
51 cumain(int argc, char *argv[])
62 parity = 0; /* none */
65 * We want to accept -# as a speed. It's easiest to look through
66 * the arguments, replace -# with -s#, and let getopt() handle it.
68 for (i = 1; i < argc; i++) {
69 if (argv[i][0] == '-' &&
70 argv[i][1] >= '0' && argv[i][1] <= '9') {
71 asprintf(&cp, "-s%s", argv[i] + 1);
74 "%s: cannot convert -# to -s#\n",
82 while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) {
90 "%s: cannot specificy multiple -l options\n",
94 if (strchr(optarg, '/'))
97 asprintf(&DV, "/dev/%s", optarg);
100 l = strtol(optarg, &cp, 10);
101 if (*cp != '\0' || l < 0 || l >= INT_MAX) {
102 fprintf(stderr, "%s: unsupported speed %s\n",
109 setboolean(value(LECHO), TRUE);
117 parity = 0; /* -e -o */
119 parity = 1; /* odd */
123 parity = 0; /* -o -e */
125 parity = -1; /* even */
146 signal(SIGINT, cleanup);
147 signal(SIGQUIT, cleanup);
148 signal(SIGHUP, cleanup);
149 signal(SIGTERM, cleanup);
150 signal(SIGCHLD, SIG_DFL);
153 * The "cu" host name is used to define the
154 * attributes of the generic dialer.
156 (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
157 if ((i = hunt(sbuf)) == 0) {
158 printf("all ports busy\n");
162 printf("link down\n");
163 (void)uu_unlock(uucplock);
166 setbuf(stdout, NULL);
181 setboolean(value(VERBOSE), FALSE);
182 if (HW && ttysetup(BR)) {
183 fprintf(stderr, "%s: unsupported speed %ld\n",
186 (void)uu_unlock(uucplock);
190 printf("Connect failed\n");
192 (void)uu_unlock(uucplock);
195 if (!HW && ttysetup(BR)) {
196 fprintf(stderr, "%s: unsupported speed %ld\n",
199 (void)uu_unlock(uucplock);
207 fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] "
208 "[-s speed | -speed] [phone-number]\n");