|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)slattach.c 4.1 (Berkeley) 2/17/86"; ! 3: #endif ! 4: #include <stdio.h> ! 5: #include <sys/param.h> ! 6: #include <sgtty.h> ! 7: #include <sys/socket.h> ! 8: #include <netinet/in.h> ! 9: #include <net/if.h> ! 10: #include <netdb.h> ! 11: #include <fcntl.h> ! 12: ! 13: #ifndef lint ! 14: static char rcsid[] = "$Header: slattach.c,v 1.1 84/10/04 12:57:12 rick Exp $"; ! 15: #endif ! 16: ! 17: #define DEFAULT_BAUD 9600 ! 18: int speed; ! 19: int slipdisc = SLIPDISC; ! 20: ! 21: char devname[32]; ! 22: char hostname[MAXHOSTNAMELEN]; ! 23: ! 24: extern int errno; ! 25: ! 26: main(argc, argv) ! 27: int argc; ! 28: char *argv[]; ! 29: { ! 30: register FILE *fp; ! 31: register int fd; ! 32: register char *dev = argv[1]; ! 33: struct sgttyb sgtty; ! 34: int n; ! 35: ! 36: if (argc < 2 || argc > 3) { ! 37: fprintf(stderr, "usage: %s ttyname [baudrate]\n", argv[0]); ! 38: exit(1); ! 39: } ! 40: speed = argc == 3 ? findspeed(atoi(argv[2])) : findspeed(DEFAULT_BAUD); ! 41: if (speed == 0) { ! 42: fprintf(stderr, "unknown speed %s", argv[2]); ! 43: exit(1); ! 44: } ! 45: if (strncmp("/dev/", dev, 5)) { ! 46: sprintf(devname, "/dev/%s", dev); ! 47: dev = devname; ! 48: } ! 49: if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { ! 50: perror(dev); ! 51: exit(1); ! 52: } ! 53: sgtty.sg_flags = RAW | ANYP; ! 54: sgtty.sg_ispeed = sgtty.sg_ospeed = speed; ! 55: if (ioctl(fd, TIOCSETP, &sgtty) < 0) { ! 56: perror("ioctl(TIOCSETP)"); ! 57: exit(1); ! 58: } ! 59: if (ioctl(fd, TIOCSETD, &slipdisc) < 0) { ! 60: perror("ioctl(TIOCSETD)"); ! 61: exit(1); ! 62: } ! 63: ! 64: if (fork() > 0) ! 65: exit(0); ! 66: for (;;) ! 67: sigpause(0); ! 68: } ! 69: ! 70: struct sg_spds { ! 71: int sp_val, sp_name; ! 72: } spds[] = { ! 73: #ifdef B50 ! 74: { 50, B50 }, ! 75: #endif ! 76: #ifdef B75 ! 77: { 75, B75 }, ! 78: #endif ! 79: #ifdef B110 ! 80: { 110, B110 }, ! 81: #endif ! 82: #ifdef B150 ! 83: { 150, B150 }, ! 84: #endif ! 85: #ifdef B200 ! 86: { 200, B200 }, ! 87: #endif ! 88: #ifdef B300 ! 89: { 300, B300 }, ! 90: #endif ! 91: #ifdef B600 ! 92: { 600, B600 }, ! 93: #endif ! 94: #ifdef B1200 ! 95: { 1200, B1200 }, ! 96: #endif ! 97: #ifdef B1800 ! 98: { 1800, B1800 }, ! 99: #endif ! 100: #ifdef B2000 ! 101: { 2000, B2000 }, ! 102: #endif ! 103: #ifdef B2400 ! 104: { 2400, B2400 }, ! 105: #endif ! 106: #ifdef B3600 ! 107: { 3600, B3600 }, ! 108: #endif ! 109: #ifdef B4800 ! 110: { 4800, B4800 }, ! 111: #endif ! 112: #ifdef B7200 ! 113: { 7200, B7200 }, ! 114: #endif ! 115: #ifdef B9600 ! 116: { 9600, B9600 }, ! 117: #endif ! 118: #ifdef EXTA ! 119: { 19200, EXTA }, ! 120: #endif ! 121: #ifdef EXTB ! 122: { 38400, EXTB }, ! 123: #endif ! 124: { 0, 0 } ! 125: }; ! 126: ! 127: findspeed(speed) ! 128: register int speed; ! 129: { ! 130: register struct sg_spds *sp; ! 131: ! 132: sp = spds; ! 133: while (sp->sp_val && sp->sp_val != speed) ! 134: sp++; ! 135: return (sp->sp_name); ! 136: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.