[BACK]Return to cu.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tip

Annotation of src/usr.bin/tip/cu.c, Revision 1.4

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