Annotation of 43BSDReno/sbin/slattach/slattach.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Rick Adams.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted
        !             9:  * provided that: (1) source distributions retain this entire copyright
        !            10:  * notice and comment, and (2) distributions including binaries display
        !            11:  * the following acknowledgement:  ``This product includes software
        !            12:  * developed by the University of California, Berkeley and its contributors''
        !            13:  * in the documentation or other materials provided with the distribution
        !            14:  * and in all advertising materials mentioning features or use of this
        !            15:  * software. Neither the name of the University nor the names of its
        !            16:  * contributors may be used to endorse or promote products derived
        !            17:  * from this software without specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: char copyright[] =
        !            25: "@(#) Copyright (c) 1988 Regents of the University of California.\n\
        !            26:  All rights reserved.\n";
        !            27: #endif /* not lint */
        !            28: 
        !            29: #ifndef lint
        !            30: static char sccsid[] = "@(#)slattach.c 4.6 (Berkeley) 6/1/90";
        !            31: #endif /* not lint */
        !            32: 
        !            33: #include <sys/param.h>
        !            34: #include <sgtty.h>
        !            35: #include <sys/socket.h>
        !            36: #include <netinet/in.h>
        !            37: #include <net/if.h>
        !            38: #include <netdb.h>
        !            39: #include <fcntl.h>
        !            40: #include <stdio.h>
        !            41: #include <paths.h>
        !            42: 
        !            43: #define DEFAULT_BAUD   9600
        !            44: int    slipdisc = SLIPDISC;
        !            45: 
        !            46: char   devname[32];
        !            47: char   hostname[MAXHOSTNAMELEN];
        !            48: 
        !            49: main(argc, argv)
        !            50:        int argc;
        !            51:        char *argv[];
        !            52: {
        !            53:        register int fd;
        !            54:        register char *dev = argv[1];
        !            55:        struct sgttyb sgtty;
        !            56:        int     speed;
        !            57: 
        !            58:        if (argc < 2 || argc > 3) {
        !            59:                fprintf(stderr, "usage: %s ttyname [baudrate]\n", argv[0]);
        !            60:                exit(1);
        !            61:        }
        !            62:        speed = argc == 3 ? findspeed(atoi(argv[2])) : findspeed(DEFAULT_BAUD);
        !            63:        if (speed == 0) {
        !            64:                fprintf(stderr, "unknown speed %s", argv[2]);
        !            65:                exit(1);
        !            66:        }
        !            67:        if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) {
        !            68:                (void)sprintf(devname, "%s/%s", _PATH_DEV, dev);
        !            69:                dev = devname;
        !            70:        }
        !            71:        if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) {
        !            72:                perror(dev);
        !            73:                exit(1);
        !            74:        }
        !            75:        sgtty.sg_flags = RAW | ANYP;
        !            76:        sgtty.sg_ispeed = sgtty.sg_ospeed = speed;
        !            77:        if (ioctl(fd, TIOCSETP, &sgtty) < 0) {
        !            78:                perror("ioctl(TIOCSETP)");
        !            79:                exit(1);
        !            80:        }
        !            81:        if (ioctl(fd, TIOCSETD, &slipdisc) < 0) {
        !            82:                perror("ioctl(TIOCSETD)");
        !            83:                exit(1);
        !            84:        }
        !            85: 
        !            86:        if (fork() > 0)
        !            87:                exit(0);
        !            88:        for (;;)
        !            89:                sigpause(0L);
        !            90: }
        !            91: 
        !            92: struct sg_spds {
        !            93:        int sp_val, sp_name;
        !            94: }       spds[] = {
        !            95: #ifdef B50
        !            96:        { 50, B50 },
        !            97: #endif
        !            98: #ifdef B75
        !            99:        { 75, B75 },
        !           100: #endif
        !           101: #ifdef B110
        !           102:        { 110, B110 },
        !           103: #endif
        !           104: #ifdef B150
        !           105:        { 150, B150 },
        !           106: #endif
        !           107: #ifdef B200
        !           108:        { 200, B200 },
        !           109: #endif
        !           110: #ifdef B300
        !           111:        { 300, B300 },
        !           112: #endif
        !           113: #ifdef B600
        !           114:        { 600, B600 },
        !           115: #endif
        !           116: #ifdef B1200
        !           117:        { 1200, B1200 },
        !           118: #endif
        !           119: #ifdef B1800
        !           120:        { 1800, B1800 },
        !           121: #endif
        !           122: #ifdef B2000
        !           123:        { 2000, B2000 },
        !           124: #endif
        !           125: #ifdef B2400
        !           126:        { 2400, B2400 },
        !           127: #endif
        !           128: #ifdef B3600
        !           129:        { 3600, B3600 },
        !           130: #endif
        !           131: #ifdef B4800
        !           132:        { 4800, B4800 },
        !           133: #endif
        !           134: #ifdef B7200
        !           135:        { 7200, B7200 },
        !           136: #endif
        !           137: #ifdef B9600
        !           138:        { 9600, B9600 },
        !           139: #endif
        !           140: #ifdef EXTA
        !           141:        { 19200, EXTA },
        !           142: #endif
        !           143: #ifdef EXTB
        !           144:        { 38400, EXTB },
        !           145: #endif
        !           146:        { 0, 0 }
        !           147: };
        !           148: 
        !           149: findspeed(speed)
        !           150:        register int speed;
        !           151: {
        !           152:        register struct sg_spds *sp;
        !           153: 
        !           154:        sp = spds;
        !           155:        while (sp->sp_val && sp->sp_val != speed)
        !           156:                sp++;
        !           157:        return (sp->sp_name);
        !           158: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.