slattach.c revision 1.14
1/* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. 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 38static char copyright[] = 39"@(#) Copyright (c) 1988, 1993\n\ 40 The Regents of the University of California. All rights reserved.\n"; 41#endif /* not lint */ 42 43#ifndef lint 44/*static char sccsid[] = "from: @(#)slattach.c 8.2 (Berkeley) 1/7/94";*/ 45static char *rcsid = "$Id: slattach.c,v 1.14 1994/12/18 00:26:34 cgd Exp $"; 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/socket.h> 50#include <sys/types.h> 51#include <sys/ioctl.h> 52 53#include <net/if.h> 54#include <netinet/in.h> 55 56#include <err.h> 57#include <fcntl.h> 58#include <netdb.h> 59#include <paths.h> 60#include <signal.h> 61#include <stdio.h> 62#include <stdlib.h> 63#include <string.h> 64#include <termios.h> 65#include <unistd.h> 66 67int speed = 9600; 68int slipdisc = SLIPDISC; 69 70char devicename[32]; 71 72void usage __P((void)); 73 74int 75main(argc, argv) 76 int argc; 77 char *argv[]; 78{ 79 register int fd; 80 register char *dev = argv[1]; 81 struct termios tty; 82 tcflag_t cflag = HUPCL; 83 int ch; 84 85 while ((ch = getopt(argc, argv, "hms:")) != -1) { 86 switch (ch) { 87 case 'h': 88 cflag |= CRTSCTS; 89 break; 90 case 'm': 91 cflag &= ~HUPCL; 92 break; 93 case 's': 94 speed = atoi(optarg); 95 break; 96 case '?': 97 default: 98 usage(); 99 } 100 } 101 argc -= optind; 102 argv += optind; 103 104 if (argc != 1) 105 usage(); 106 107 dev = *argv; 108 if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { 109 (void)snprintf(devicename, sizeof(devicename), 110 "%s%s", _PATH_DEV, dev); 111 dev = devicename; 112 } 113 if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { 114 perror(dev); 115 exit(1); 116 } 117 tty.c_cflag = CREAD | CS8 | cflag; 118 tty.c_iflag = 0; 119 tty.c_lflag = 0; 120 tty.c_oflag = 0; 121 tty.c_cc[VMIN] = 1; 122 tty.c_cc[VTIME] = 0; 123 cfsetspeed(&tty, speed); 124 if (tcsetattr(fd, TCSADRAIN, &tty) < 0) 125 err(1, "tcsetattr"); 126 if (ioctl(fd, TIOCSDTR, 0) < 0) 127 err(1, "TIOCSDTR"); 128 if (ioctl(fd, TIOCSETD, &slipdisc) < 0) 129 err(1, "TIOCSETD"); 130 131 if (fork() > 0) 132 exit(0); 133 for (;;) 134 sigpause(0L); 135} 136 137void 138usage() 139{ 140 141 (void)fprintf(stderr, "usage: slattach [-hm] [-s baudrate] ttyname\n"); 142 exit(1); 143} 144