[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.10

1.10    ! pvalchev    1: /*     $OpenBSD: cu.c,v 1.9 2001/09/24 17:43:15 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.10    ! pvalchev   41: static char rcsid[] = "$OpenBSD: cu.c,v 1.9 2001/09/24 17:43:15 millert Exp $";
1.1       deraadt    42: #endif /* not lint */
                     43:
                     44: #include "tip.h"
                     45:
                     46: void   cleanup();
1.6       millert    47: void   cuusage();
1.1       deraadt    48:
                     49: /*
                     50:  * Botch the interface to look like cu's
                     51:  */
1.4       deraadt    52: void
1.1       deraadt    53: cumain(argc, argv)
1.4       deraadt    54:        int argc;
1.1       deraadt    55:        char *argv[];
                     56: {
1.6       millert    57:        int ch, i;
                     58:        long l;
                     59:        char *cp;
1.1       deraadt    60:        static char sbuf[12];
                     61:
1.6       millert    62:        if (argc < 2)
                     63:                cuusage();
1.1       deraadt    64:        CU = DV = NOSTR;
                     65:        BR = DEFBR;
1.6       millert    66:        while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
                     67:                switch(ch) {
1.1       deraadt    68:                case 'a':
1.6       millert    69:                        CU = optarg;
                     70:                        break;
                     71:                case 'l':
1.8       deraadt    72:                        if (DV != NULL) {
                     73:                                fprintf(stderr,
                     74:                                    "%s: cannot specificy multiple -l options\n",
                     75:                                    __progname);
                     76:                                exit(3);
                     77:                        }
                     78:                        if (strchr(optarg, '/'))
                     79:                                DV = optarg;
                     80:                        else
                     81:                                asprintf(&DV, "/dev/%s", optarg);
1.1       deraadt    82:                        break;
                     83:                case 's':
1.6       millert    84:                        l = strtol(optarg, &cp, 10);
                     85:                        if (*cp != '\0' || l < 0 || l >= INT_MAX ||
                     86:                            speed((int)l) == 0) {
                     87:                                fprintf(stderr, "%s: unsupported speed %s\n",
                     88:                                    __progname, optarg);
1.1       deraadt    89:                                exit(3);
                     90:                        }
1.6       millert    91:                        BR = (int)l;
                     92:                        break;
                     93:                case 'h':
1.9       millert    94:                        setboolean(value(LECHO), TRUE);
1.6       millert    95:                        HD = TRUE;
                     96:                        break;
                     97:                case 't':
                     98:                        HW = 1, DU = -1;
1.1       deraadt    99:                        break;
1.6       millert   100:                case 'o':
                    101:                        setparity("odd");
                    102:                        break;
                    103:                case 'e':
                    104:                        setparity("even");
1.1       deraadt   105:                        break;
                    106:                case '0': case '1': case '2': case '3': case '4':
                    107:                case '5': case '6': case '7': case '8': case '9':
                    108:                        if (CU)
1.6       millert   109:                                CU[strlen(CU)-1] = ch;
1.1       deraadt   110:                        if (DV)
1.6       millert   111:                                DV[strlen(DV)-1] = ch;
1.1       deraadt   112:                        break;
                    113:                default:
1.10    ! pvalchev  114:                        cuusage();
1.1       deraadt   115:                        break;
                    116:                }
                    117:        }
1.6       millert   118:        argc -= optind;
                    119:        argv += optind;
                    120:
                    121:        switch (argc) {
                    122:        case 1:
                    123:                PN = argv[0];
                    124:                break;
                    125:        case 0:
                    126:                break;
                    127:        default:
                    128:                cuusage();
                    129:                break;
                    130:        }
                    131:
1.1       deraadt   132:        signal(SIGINT, cleanup);
                    133:        signal(SIGQUIT, cleanup);
                    134:        signal(SIGHUP, cleanup);
                    135:        signal(SIGTERM, cleanup);
                    136:
                    137:        /*
                    138:         * The "cu" host name is used to define the
                    139:         * attributes of the generic dialer.
                    140:         */
1.4       deraadt   141:        (void)snprintf(sbuf, sizeof(sbuf), "cu%ld", BR);
1.1       deraadt   142:        if ((i = hunt(sbuf)) == 0) {
                    143:                printf("all ports busy\n");
                    144:                exit(3);
                    145:        }
                    146:        if (i == -1) {
                    147:                printf("link down\n");
                    148:                (void)uu_unlock(uucplock);
                    149:                exit(3);
                    150:        }
                    151:        setbuf(stdout, NULL);
                    152:        loginit();
                    153:        user_uid();
                    154:        vinit();
                    155:        setparity("none");
1.9       millert   156:        setboolean(value(VERBOSE), FALSE);
1.1       deraadt   157:        if (HW)
                    158:                ttysetup(speed(BR));
                    159:        if (connect()) {
                    160:                printf("Connect failed\n");
                    161:                daemon_uid();
                    162:                (void)uu_unlock(uucplock);
                    163:                exit(1);
                    164:        }
                    165:        if (!HW)
                    166:                ttysetup(speed(BR));
1.6       millert   167: }
                    168:
                    169: void
                    170: cuusage()
                    171: {
                    172:        fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] "
                    173:            "[phone-number]\n");
                    174:        exit(8);
1.1       deraadt   175: }