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 slipdisc = SLIPDISC; 19: 20: char devname[32]; 21: char hostname[MAXHOSTNAMELEN]; 22: 23: main(argc, argv) 24: int argc; 25: char *argv[]; 26: { 27: register int fd; 28: register char *dev = argv[1]; 29: struct sgttyb sgtty; 30: int speed; 31: 32: if (argc < 2 || argc > 3) { 33: fprintf(stderr, "usage: %s ttyname [baudrate]\n", argv[0]); 34: exit(1); 35: } 36: speed = argc == 3 ? findspeed(atoi(argv[2])) : findspeed(DEFAULT_BAUD); 37: if (speed == 0) { 38: fprintf(stderr, "unknown speed %s", argv[2]); 39: exit(1); 40: } 41: if (strncmp("/dev/", dev, 5)) { 42: (void)sprintf(devname, "/dev/%s", dev); 43: dev = devname; 44: } 45: if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { 46: perror(dev); 47: exit(1); 48: } 49: sgtty.sg_flags = RAW | ANYP; 50: sgtty.sg_ispeed = sgtty.sg_ospeed = speed; 51: if (ioctl(fd, TIOCSETP, &sgtty) < 0) { 52: perror("ioctl(TIOCSETP)"); 53: exit(1); 54: } 55: if (ioctl(fd, TIOCSETD, &slipdisc) < 0) { 56: perror("ioctl(TIOCSETD)"); 57: exit(1); 58: } 59: 60: if (fork() > 0) 61: exit(0); 62: for (;;) 63: sigpause(0L); 64: } 65: 66: struct sg_spds { 67: int sp_val, sp_name; 68: } spds[] = { 69: #ifdef B50 70: { 50, B50 }, 71: #endif 72: #ifdef B75 73: { 75, B75 }, 74: #endif 75: #ifdef B110 76: { 110, B110 }, 77: #endif 78: #ifdef B150 79: { 150, B150 }, 80: #endif 81: #ifdef B200 82: { 200, B200 }, 83: #endif 84: #ifdef B300 85: { 300, B300 }, 86: #endif 87: #ifdef B600 88: { 600, B600 }, 89: #endif 90: #ifdef B1200 91: { 1200, B1200 }, 92: #endif 93: #ifdef B1800 94: { 1800, B1800 }, 95: #endif 96: #ifdef B2000 97: { 2000, B2000 }, 98: #endif 99: #ifdef B2400 100: { 2400, B2400 }, 101: #endif 102: #ifdef B3600 103: { 3600, B3600 }, 104: #endif 105: #ifdef B4800 106: { 4800, B4800 }, 107: #endif 108: #ifdef B7200 109: { 7200, B7200 }, 110: #endif 111: #ifdef B9600 112: { 9600, B9600 }, 113: #endif 114: #ifdef EXTA 115: { 19200, EXTA }, 116: #endif 117: #ifdef EXTB 118: { 38400, EXTB }, 119: #endif 120: { 0, 0 } 121: }; 122: 123: findspeed(speed) 124: register int speed; 125: { 126: register struct sg_spds *sp; 127: 128: sp = spds; 129: while (sp->sp_val && sp->sp_val != speed) 130: sp++; 131: return (sp->sp_name); 132: }