slattach.c revision 1.2
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, 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 38char copyright[] = 39"@(#) Copyright (c) 1988 Regents of the University of California.\n\ 40 All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44static char sccsid[] = "@(#)slattach.c 4.6 (Berkeley) 6/1/90"; 45static char rcsid[] = "$Id: slattach.c,v 1.2 1993/03/22 08:04:00 cgd Exp $"; 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sgtty.h> 50#include <sys/socket.h> 51#include <netinet/in.h> 52#include <net/if.h> 53#include <netdb.h> 54#include <fcntl.h> 55#include <stdio.h> 56#include <paths.h> 57 58#define DEFAULT_BAUD 9600 59int slipdisc = SLIPDISC; 60 61char devname[32]; 62char hostname[MAXHOSTNAMELEN]; 63 64main(argc, argv) 65 int argc; 66 char *argv[]; 67{ 68 register int fd; 69 register char *dev = argv[1]; 70 struct sgttyb sgtty; 71 int speed; 72 73 if (argc < 2 || argc > 3) { 74 fprintf(stderr, "usage: %s ttyname [baudrate]\n", argv[0]); 75 exit(1); 76 } 77 speed = argc == 3 ? findspeed(atoi(argv[2])) : findspeed(DEFAULT_BAUD); 78 if (speed == 0) { 79 fprintf(stderr, "unknown speed %s", argv[2]); 80 exit(1); 81 } 82 if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { 83 (void)sprintf(devname, "%s/%s", _PATH_DEV, dev); 84 dev = devname; 85 } 86 if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { 87 perror(dev); 88 exit(1); 89 } 90 sgtty.sg_flags = RAW | ANYP; 91 sgtty.sg_ispeed = sgtty.sg_ospeed = speed; 92 if (ioctl(fd, TIOCSETP, &sgtty) < 0) { 93 perror("ioctl(TIOCSETP)"); 94 exit(1); 95 } 96 if (ioctl(fd, TIOCSETD, &slipdisc) < 0) { 97 perror("ioctl(TIOCSETD)"); 98 exit(1); 99 } 100 101 if (fork() > 0) 102 exit(0); 103 for (;;) 104 sigpause(0L); 105} 106 107struct sg_spds { 108 int sp_val, sp_name; 109} spds[] = { 110#ifdef B50 111 { 50, B50 }, 112#endif 113#ifdef B75 114 { 75, B75 }, 115#endif 116#ifdef B110 117 { 110, B110 }, 118#endif 119#ifdef B150 120 { 150, B150 }, 121#endif 122#ifdef B200 123 { 200, B200 }, 124#endif 125#ifdef B300 126 { 300, B300 }, 127#endif 128#ifdef B600 129 { 600, B600 }, 130#endif 131#ifdef B1200 132 { 1200, B1200 }, 133#endif 134#ifdef B1800 135 { 1800, B1800 }, 136#endif 137#ifdef B2000 138 { 2000, B2000 }, 139#endif 140#ifdef B2400 141 { 2400, B2400 }, 142#endif 143#ifdef B3600 144 { 3600, B3600 }, 145#endif 146#ifdef B4800 147 { 4800, B4800 }, 148#endif 149#ifdef B7200 150 { 7200, B7200 }, 151#endif 152#ifdef B9600 153 { 9600, B9600 }, 154#endif 155#ifdef EXTA 156 { 19200, EXTA }, 157#endif 158#ifdef EXTB 159 { 38400, EXTB }, 160#endif 161 { 0, 0 } 162}; 163 164findspeed(speed) 165 register int speed; 166{ 167 register struct sg_spds *sp; 168 169 sp = spds; 170 while (sp->sp_val && sp->sp_val != speed) 171 sp++; 172 return (sp->sp_name); 173} 174