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

1.18    ! moritz      1: /*     $OpenBSD: cu.c,v 1.17 2006/03/16 19:32:46 deraadt 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.
1.14      millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #ifndef lint
                     34: #if 0
                     35: static char sccsid[] = "@(#)cu.c       8.1 (Berkeley) 6/6/93";
                     36: #endif
1.18    ! moritz     37: static const char rcsid[] = "$OpenBSD: cu.c,v 1.17 2006/03/16 19:32:46 deraadt Exp $";
1.1       deraadt    38: #endif /* not lint */
                     39:
                     40: #include "tip.h"
                     41:
1.18    ! moritz     42: static void    cuusage(void);
1.1       deraadt    43:
                     44: /*
                     45:  * Botch the interface to look like cu's
                     46:  */
1.4       deraadt    47: void
1.17      deraadt    48: cumain(int argc, char *argv[])
1.1       deraadt    49: {
1.11      miod       50:        int ch, i, parity;
1.6       millert    51:        long l;
                     52:        char *cp;
1.1       deraadt    53:        static char sbuf[12];
                     54:
1.6       millert    55:        if (argc < 2)
                     56:                cuusage();
1.1       deraadt    57:        CU = DV = NOSTR;
                     58:        BR = DEFBR;
1.11      miod       59:        parity = 0;     /* none */
1.6       millert    60:        while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) {
1.17      deraadt    61:                switch (ch) {
1.1       deraadt    62:                case 'a':
1.6       millert    63:                        CU = optarg;
                     64:                        break;
                     65:                case 'l':
1.8       deraadt    66:                        if (DV != NULL) {
                     67:                                fprintf(stderr,
                     68:                                    "%s: cannot specificy multiple -l options\n",
                     69:                                    __progname);
                     70:                                exit(3);
                     71:                        }
                     72:                        if (strchr(optarg, '/'))
                     73:                                DV = optarg;
                     74:                        else
                     75:                                asprintf(&DV, "/dev/%s", optarg);
1.1       deraadt    76:                        break;
                     77:                case 's':
1.6       millert    78:                        l = strtol(optarg, &cp, 10);
1.13      millert    79:                        if (*cp != '\0' || l < 0 || l >= INT_MAX) {
1.6       millert    80:                                fprintf(stderr, "%s: unsupported speed %s\n",
                     81:                                    __progname, optarg);
1.1       deraadt    82:                                exit(3);
                     83:                        }
1.6       millert    84:                        BR = (int)l;
                     85:                        break;
                     86:                case 'h':
1.9       millert    87:                        setboolean(value(LECHO), TRUE);
1.6       millert    88:                        HD = TRUE;
                     89:                        break;
                     90:                case 't':
                     91:                        HW = 1, DU = -1;
1.1       deraadt    92:                        break;
1.6       millert    93:                case 'o':
1.11      miod       94:                        if (parity != 0)
                     95:                                parity = 0;     /* -e -o */
                     96:                        else
                     97:                                parity = 1;     /* odd */
1.6       millert    98:                        break;
                     99:                case 'e':
1.11      miod      100:                        if (parity != 0)
                    101:                                parity = 0;     /* -o -e */
                    102:                        else
                    103:                                parity = -1;    /* even */
1.1       deraadt   104:                        break;
                    105:                case '0': case '1': case '2': case '3': case '4':
                    106:                case '5': case '6': case '7': case '8': case '9':
                    107:                        if (CU)
1.6       millert   108:                                CU[strlen(CU)-1] = ch;
1.1       deraadt   109:                        if (DV)
1.6       millert   110:                                DV[strlen(DV)-1] = ch;
1.1       deraadt   111:                        break;
                    112:                default:
1.10      pvalchev  113:                        cuusage();
1.1       deraadt   114:                        break;
                    115:                }
                    116:        }
1.6       millert   117:        argc -= optind;
                    118:        argv += optind;
                    119:
                    120:        switch (argc) {
                    121:        case 1:
                    122:                PN = argv[0];
                    123:                break;
                    124:        case 0:
                    125:                break;
                    126:        default:
                    127:                cuusage();
                    128:                break;
                    129:        }
                    130:
1.1       deraadt   131:        signal(SIGINT, cleanup);
                    132:        signal(SIGQUIT, cleanup);
                    133:        signal(SIGHUP, cleanup);
                    134:        signal(SIGTERM, cleanup);
1.16      otto      135:        signal(SIGCHLD, SIG_DFL);
1.1       deraadt   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();
1.11      miod      155:        switch (parity) {
                    156:        case -1:
                    157:                setparity("even");
                    158:                break;
                    159:        case 1:
                    160:                setparity("odd");
                    161:                break;
                    162:        default:
                    163:                setparity("none");
                    164:                break;
                    165:        }
1.9       millert   166:        setboolean(value(VERBOSE), FALSE);
1.13      millert   167:        if (HW && ttysetup(BR)) {
                    168:                fprintf(stderr, "%s: unsupported speed %ld\n",
                    169:                    __progname, BR);
                    170:                daemon_uid();
                    171:                (void)uu_unlock(uucplock);
                    172:                exit(3);
                    173:        }
1.17      deraadt   174:        if (con()) {
1.1       deraadt   175:                printf("Connect failed\n");
                    176:                daemon_uid();
                    177:                (void)uu_unlock(uucplock);
                    178:                exit(1);
                    179:        }
1.13      millert   180:        if (!HW && ttysetup(BR)) {
                    181:                fprintf(stderr, "%s: unsupported speed %ld\n",
                    182:                    __progname, BR);
                    183:                daemon_uid();
                    184:                (void)uu_unlock(uucplock);
                    185:                exit(3);
                    186:        }
1.6       millert   187: }
                    188:
1.18    ! moritz    189: static void
1.17      deraadt   190: cuusage(void)
1.6       millert   191: {
                    192:        fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] "
                    193:            "[phone-number]\n");
                    194:        exit(8);
1.1       deraadt   195: }