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 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 1983, 1993
8 * The Regents of the University of California. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
40 static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
41 static const char rcsid[] = "$OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $";
47 static void cuusage(void);
50 * Botch the interface to look like cu's
53 cumain(int argc, char *argv[])
64 parity = 0; /* none */
67 * We want to accept -# as a speed. It's easiest to look through
68 * the arguments, replace -# with -s#, and let getopt() handle it.
70 for (i = 1; i < argc; i++) {
71 if (argv[i][0] == '-' &&
72 argv[i][1] >= '0' && argv[i][1] <= '9') {
73 asprintf(&cp, "-s%s", argv[i] + 1);
76 "%s: cannot convert -# to -s#\n",
84 while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) {
92 "%s: cannot specificy multiple -l options\n",
96 if (strchr(optarg, '/'))
99 asprintf(&DV, "/dev/%s", optarg);
102 l = strtol(optarg, &cp, 10);
103 if (*cp != '\0' || l < 0 || l >= INT_MAX) {
104 fprintf(stderr, "%s: unsupported speed %s\n",
111 setboolean(value(LECHO), TRUE);
119 parity = 0; /* -e -o */
121 parity = 1; /* odd */
125 parity = 0; /* -o -e */
127 parity = -1; /* even */
148 signal(SIGINT, cleanup);
149 signal(SIGQUIT, cleanup);
150 signal(SIGHUP, cleanup);
151 signal(SIGTERM, cleanup);
152 signal(SIGCHLD, SIG_DFL);
155 * The "cu" host name is used to define the
156 * attributes of the generic dialer.
158 (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
159 if ((i = hunt(sbuf)) == 0) {
160 printf("all ports busy\n");
164 printf("link down\n");
165 (void)uu_unlock(uucplock);
168 setbuf(stdout, NULL);
183 setboolean(value(VERBOSE), FALSE);
184 if (HW && ttysetup(BR)) {
185 fprintf(stderr, "%s: unsupported speed %ld\n",
188 (void)uu_unlock(uucplock);
192 printf("Connect failed\n");
194 (void)uu_unlock(uucplock);
197 if (!HW && ttysetup(BR)) {
198 fprintf(stderr, "%s: unsupported speed %ld\n",
201 (void)uu_unlock(uucplock);
209 fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] "
210 "[-s speed | -speed] [phone-number]\n");