slattach.c revision 1.15
1/* $NetBSD: slattach.c,v 1.15 1995/03/18 15:01:14 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1988, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Rick Adams. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39#ifndef lint 40static char copyright[] = 41"@(#) Copyright (c) 1988, 1993\n\ 42 The Regents of the University of California. All rights reserved.\n"; 43#endif /* not lint */ 44 45#ifndef lint 46#if 0 47static char sccsid[] = "@(#)slattach.c 8.2 (Berkeley) 1/7/94"; 48#else 49static char rcsid[] = "$NetBSD: slattach.c,v 1.15 1995/03/18 15:01:14 cgd Exp $"; 50#endif 51#endif /* not lint */ 52 53#include <sys/param.h> 54#include <sys/socket.h> 55#include <sys/types.h> 56#include <sys/ioctl.h> 57 58#include <net/if.h> 59#include <netinet/in.h> 60 61#include <err.h> 62#include <fcntl.h> 63#include <netdb.h> 64#include <paths.h> 65#include <signal.h> 66#include <stdio.h> 67#include <stdlib.h> 68#include <string.h> 69#include <termios.h> 70#include <unistd.h> 71 72int speed = 9600; 73int slipdisc = SLIPDISC; 74 75char devicename[32]; 76 77void usage __P((void)); 78 79int 80main(argc, argv) 81 int argc; 82 char *argv[]; 83{ 84 register int fd; 85 register char *dev = argv[1]; 86 struct termios tty; 87 tcflag_t cflag = HUPCL; 88 int ch; 89 90 while ((ch = getopt(argc, argv, "hms:")) != -1) { 91 switch (ch) { 92 case 'h': 93 cflag |= CRTSCTS; 94 break; 95 case 'm': 96 cflag &= ~HUPCL; 97 break; 98 case 's': 99 speed = atoi(optarg); 100 break; 101 case '?': 102 default: 103 usage(); 104 } 105 } 106 argc -= optind; 107 argv += optind; 108 109 if (argc != 1) 110 usage(); 111 112 dev = *argv; 113 if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { 114 (void)snprintf(devicename, sizeof(devicename), 115 "%s%s", _PATH_DEV, dev); 116 dev = devicename; 117 } 118 if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { 119 perror(dev); 120 exit(1); 121 } 122 tty.c_cflag = CREAD | CS8 | cflag; 123 tty.c_iflag = 0; 124 tty.c_lflag = 0; 125 tty.c_oflag = 0; 126 tty.c_cc[VMIN] = 1; 127 tty.c_cc[VTIME] = 0; 128 cfsetspeed(&tty, speed); 129 if (tcsetattr(fd, TCSADRAIN, &tty) < 0) 130 err(1, "tcsetattr"); 131 if (ioctl(fd, TIOCSDTR, 0) < 0) 132 err(1, "TIOCSDTR"); 133 if (ioctl(fd, TIOCSETD, &slipdisc) < 0) 134 err(1, "TIOCSETD"); 135 136 if (fork() > 0) 137 exit(0); 138 for (;;) 139 sigpause(0L); 140} 141 142void 143usage() 144{ 145 146 (void)fprintf(stderr, "usage: slattach [-hm] [-s baudrate] ttyname\n"); 147 exit(1); 148} 149