1 /* $NetBSD: cu.c,v 1.6 1997/11/22 07:28:42 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #include <sys/cdefs.h> 37 #ifndef lint 38 #if 0 39 static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; 40 #endif 41 __RCSID("$NetBSD: cu.c,v 1.6 1997/11/22 07:28:42 lukem Exp $"); 42 #endif /* not lint */ 43 44 #include "tip.h" 45 46 /* 47 * Botch the interface to look like cu's 48 */ 49 int 50 cumain(argc, argv) 51 char *argv[]; 52 { 53 int i; 54 static char sbuf[12]; 55 56 if (argc < 2) { 57 fprintf(stderr, 58 "usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n"); 59 exit(8); 60 } 61 CU = DV = NULL; 62 BR = DEFBR; 63 for (; argc > 1; argv++, argc--) { 64 if (argv[1][0] != '-') 65 PN = argv[1]; 66 else switch (argv[1][1]) { 67 68 case 't': 69 HW = 1, DU = -1; 70 --argc; 71 continue; 72 73 case 'a': 74 CU = argv[2]; ++argv; --argc; 75 break; 76 77 case 's': 78 if (argc < 3 || speed(atoi(argv[2])) == 0) { 79 fprintf(stderr, "cu: unsupported speed %s\n", 80 argv[2]); 81 exit(3); 82 } 83 BR = atoi(argv[2]); ++argv; --argc; 84 break; 85 86 case 'l': 87 DV = argv[2]; ++argv; --argc; 88 break; 89 90 case '0': case '1': case '2': case '3': case '4': 91 case '5': case '6': case '7': case '8': case '9': 92 if (CU) 93 CU[strlen(CU)-1] = argv[1][1]; 94 if (DV) 95 DV[strlen(DV)-1] = argv[1][1]; 96 break; 97 98 default: 99 printf("Bad flag %s", argv[1]); 100 break; 101 } 102 } 103 signal(SIGINT, cleanup); 104 signal(SIGQUIT, cleanup); 105 signal(SIGHUP, cleanup); 106 signal(SIGTERM, cleanup); 107 108 /* 109 * The "cu" host name is used to define the 110 * attributes of the generic dialer. 111 */ 112 (void)snprintf(sbuf, sizeof sbuf, "cu%d", (int)BR); 113 if ((i = hunt(sbuf)) == 0) { 114 printf("all ports busy\n"); 115 exit(3); 116 } 117 if (i == -1) { 118 printf("link down\n"); 119 (void)uu_unlock(uucplock); 120 exit(3); 121 } 122 setbuf(stdout, NULL); 123 loginit(); 124 user_uid(); 125 vinit(); 126 setparity("none"); 127 setboolean(value(VERBOSE), 0); 128 if (HW) 129 ttysetup(speed(BR)); 130 if (connect()) { 131 printf("Connect failed\n"); 132 daemon_uid(); 133 (void)uu_unlock(uucplock); 134 exit(1); 135 } 136 if (!HW) 137 ttysetup(speed(BR)); 138 exit(0); 139 } 140