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