cu.c revision 161754
11590Srgrimes/* $OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $ */ 21590Srgrimes/* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */ 31590Srgrimes 41590Srgrimes/* 51590Srgrimes * Copyright (c) 1983, 1993 61590Srgrimes * The Regents of the University of California. All rights reserved. 71590Srgrimes * 81590Srgrimes * Redistribution and use in source and binary forms, with or without 91590Srgrimes * modification, are permitted provided that the following conditions 101590Srgrimes * are met: 111590Srgrimes * 1. Redistributions of source code must retain the above copyright 121590Srgrimes * notice, this list of conditions and the following disclaimer. 131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141590Srgrimes * notice, this list of conditions and the following disclaimer in the 151590Srgrimes * documentation and/or other materials provided with the distribution. 161590Srgrimes * 3. Neither the name of the University nor the names of its contributors 171590Srgrimes * may be used to endorse or promote products derived from this software 181590Srgrimes * without specific prior written permission. 191590Srgrimes * 201590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301590Srgrimes * SUCH DAMAGE. 3141568Sarchie */ 321590Srgrimes 331590Srgrimes#include <sys/cdefs.h> 341590Srgrimes__FBSDID("$FreeBSD: head/usr.bin/tip/tip/cu.c 161754 2006-08-31 14:14:30Z ru $"); 351590Srgrimes 361590Srgrimes#ifndef lint 3727147Scharnier#if 0 381590Srgrimesstatic char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; 3958606Scharnierstatic const char rcsid[] = "$OpenBSD: cu.c,v 1.19 2006/05/25 08:41:52 jmc Exp $"; 401590Srgrimes#endif 4199112Sobrien#endif /* not lint */ 4299112Sobrien 431590Srgrimes#include "tip.h" 4427147Scharnier 4558606Scharnierstatic void cuusage(void); 4698251Stjr 471590Srgrimes/* 4878718Sdd * Botch the interface to look like cu's 4927147Scharnier */ 50131051Stjrvoid 51200462Sdelphijcumain(int argc, char *argv[]) 5227147Scharnier{ 531590Srgrimes int ch, i, parity; 541590Srgrimes long l; 551590Srgrimes char *cp; 561590Srgrimes static char sbuf[12]; 571590Srgrimes 581590Srgrimes if (argc < 2) 5992920Simp cuusage(); 6092920Simp CU = DV = NOSTR; 6127147Scharnier BR = DEFBR; 6227147Scharnier parity = 0; /* none */ 63102944Sdwmalone while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { 641590Srgrimes switch (ch) { 65131051Stjr case 'a': 66131051Stjr CU = optarg; 67102944Sdwmalone break; 68102944Sdwmalone case 'l': 6997216Stjr if (DV != NULL) { 70131051Stjr fprintf(stderr, 711590Srgrimes "%s: cannot specificy multiple -l options\n", 7298251Stjr __progname); 7398251Stjr exit(3); 7427147Scharnier } 7598251Stjr if (strchr(optarg, '/')) 7698251Stjr DV = optarg; 7727147Scharnier else 7827147Scharnier asprintf(&DV, "/dev/%s", optarg); 7927147Scharnier break; 8027147Scharnier case 's': 8127147Scharnier l = strtol(optarg, &cp, 10); 8227147Scharnier if (*cp != '\0' || l < 0 || l >= INT_MAX) { 8327147Scharnier fprintf(stderr, "%s: unsupported speed %s\n", 8427147Scharnier __progname, optarg); 8527147Scharnier exit(3); 8627147Scharnier } 8727147Scharnier BR = (int)l; 8827147Scharnier break; 8927147Scharnier case 'h': 9027147Scharnier setboolean(value(LECHO), TRUE); 9127147Scharnier HD = TRUE; 9227147Scharnier break; 9327147Scharnier case 't': 9427147Scharnier HW = 1, DU = -1; 9597216Stjr break; 961590Srgrimes case 'o': 971590Srgrimes if (parity != 0) 9897216Stjr parity = 0; /* -e -o */ 9997216Stjr else 10097216Stjr parity = 1; /* odd */ 10197216Stjr break; 10297216Stjr case 'e': 10397216Stjr if (parity != 0) 104131051Stjr parity = 0; /* -o -e */ 1051590Srgrimes else 106131051Stjr parity = -1; /* even */ 107131051Stjr break; 1081590Srgrimes case '0': case '1': case '2': case '3': case '4': 109131051Stjr case '5': case '6': case '7': case '8': case '9': 110131051Stjr if (CU) 1111590Srgrimes CU[strlen(CU)-1] = ch; 1121590Srgrimes if (DV) 1131590Srgrimes DV[strlen(DV)-1] = ch; 114131051Stjr break; 1151590Srgrimes default: 1161590Srgrimes cuusage(); 1171590Srgrimes break; 1181590Srgrimes } 1191590Srgrimes } 1201590Srgrimes argc -= optind; 121131051Stjr argv += optind; 1221590Srgrimes 1231590Srgrimes switch (argc) { 1241590Srgrimes case 1: 1251590Srgrimes PN = argv[0]; 1261590Srgrimes break; 1271590Srgrimes case 0: 1281590Srgrimes break; 1291590Srgrimes default: 130131051Stjr cuusage(); 1311590Srgrimes break; 1321590Srgrimes } 1331590Srgrimes 1341590Srgrimes signal(SIGINT, cleanup); 135131051Stjr signal(SIGQUIT, cleanup); 1361590Srgrimes signal(SIGHUP, cleanup); 1371590Srgrimes signal(SIGTERM, cleanup); 1381590Srgrimes signal(SIGCHLD, SIG_DFL); 1391590Srgrimes 1401590Srgrimes /* 1411590Srgrimes * The "cu" host name is used to define the 1421590Srgrimes * attributes of the generic dialer. 143131051Stjr */ 1441590Srgrimes (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR); 1451590Srgrimes if ((i = hunt(sbuf)) == 0) { 1461590Srgrimes printf("all ports busy\n"); 147131051Stjr exit(3); 148131051Stjr } 149131051Stjr if (i == -1) { 1501590Srgrimes printf("link down\n"); 1511590Srgrimes (void)uu_unlock(uucplock); 1521590Srgrimes exit(3); 153131051Stjr } 1541590Srgrimes setbuf(stdout, NULL); 1551590Srgrimes loginit(); 1561590Srgrimes user_uid(); 1571590Srgrimes vinit(); 158131051Stjr switch (parity) { 159131051Stjr case -1: 160131051Stjr setparity("even"); 161131051Stjr break; 1621590Srgrimes case 1: 16397216Stjr setparity("odd"); 1641590Srgrimes break; 1651590Srgrimes default: 16627147Scharnier setparity("none"); 167102944Sdwmalone break; 1681590Srgrimes } 169102944Sdwmalone setboolean(value(VERBOSE), FALSE); 1701590Srgrimes if (HW && ttysetup(BR)) { 1711590Srgrimes fprintf(stderr, "%s: unsupported speed %ld\n", 1721590Srgrimes __progname, BR); 1731590Srgrimes daemon_uid(); 1741590Srgrimes (void)uu_unlock(uucplock); 1751590Srgrimes exit(3); 17678482Sdd } 17758606Scharnier if (con()) { 1781590Srgrimes printf("Connect failed\n"); 17958606Scharnier daemon_uid(); 18091740Sru (void)uu_unlock(uucplock); 18191740Sru exit(1); 1821590Srgrimes } 1831590Srgrimes if (!HW && ttysetup(BR)) { 1841590Srgrimes fprintf(stderr, "%s: unsupported speed %ld\n", 18598251Stjr __progname, BR); 18658606Scharnier daemon_uid(); 18727147Scharnier (void)uu_unlock(uucplock); 1881590Srgrimes exit(3); 1891590Srgrimes } 19027147Scharnier} 19127147Scharnier 192102944Sdwmalonestatic void 19327147Scharniercuusage(void) 19427147Scharnier{ 19527147Scharnier fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] " 19627147Scharnier "[-s speed | -speed] [phone-number]\n"); 197 exit(8); 198} 199