1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 static char sccsid[] = "@(#)cu.c 5.4 (Berkeley) 09/14/87"; 9 #endif not lint 10 11 #include "tip.h" 12 13 int cleanup(); 14 int timeout(); 15 16 /* 17 * Botch the interface to look like cu's 18 */ 19 cumain(argc, argv) 20 char *argv[]; 21 { 22 register int i; 23 static char sbuf[12]; 24 25 if (argc < 2) { 26 printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n"); 27 exit(8); 28 } 29 CU = DV = NOSTR; 30 BR = DEFBR; 31 for (; argc > 1; argv++, argc--) { 32 if (argv[1][0] != '-') 33 PN = argv[1]; 34 else switch (argv[1][1]) { 35 36 case 't': 37 HW = 1, DU = -1; 38 --argc; 39 continue; 40 41 case 'a': 42 CU = argv[2]; ++argv; --argc; 43 break; 44 45 case 's': 46 if (argc < 3 || speed(atoi(argv[2])) == 0) { 47 fprintf(stderr, "cu: unsupported speed %s\n", 48 argv[2]); 49 exit(3); 50 } 51 BR = atoi(argv[2]); ++argv; --argc; 52 break; 53 54 case 'l': 55 DV = argv[2]; ++argv; --argc; 56 break; 57 58 case '0': case '1': case '2': case '3': case '4': 59 case '5': case '6': case '7': case '8': case '9': 60 if (CU) 61 CU[strlen(CU)-1] = argv[1][1]; 62 if (DV) 63 DV[strlen(DV)-1] = argv[1][1]; 64 break; 65 66 default: 67 printf("Bad flag %s", argv[1]); 68 break; 69 } 70 } 71 signal(SIGINT, cleanup); 72 signal(SIGQUIT, cleanup); 73 signal(SIGHUP, cleanup); 74 signal(SIGTERM, cleanup); 75 76 /* 77 * The "cu" host name is used to define the 78 * attributes of the generic dialer. 79 */ 80 if ((i = hunt(sprintf(sbuf, "cu%d", BR))) == 0) { 81 printf("all ports busy\n"); 82 exit(3); 83 } 84 if (i == -1) { 85 printf("link down\n"); 86 delock(uucplock); 87 exit(3); 88 } 89 setbuf(stdout, NULL); 90 loginit(); 91 user_uid(); 92 vinit(); 93 setparity("none"); 94 boolean(value(VERBOSE)) = 0; 95 if (HW) 96 ttysetup(speed(BR)); 97 if (connect()) { 98 printf("Connect failed\n"); 99 daemon_uid(); 100 delock(uucplock); 101 exit(1); 102 } 103 if (!HW) 104 ttysetup(speed(BR)); 105 } 106