slattach.c revision 1.13
11.1Scgd/* 21.12Smycroft * Copyright (c) 1988, 1993 31.12Smycroft * The Regents of the University of California. All rights reserved. 41.1Scgd * 51.1Scgd * This code is derived from software contributed to Berkeley by 61.1Scgd * Rick Adams. 71.1Scgd * 81.1Scgd * Redistribution and use in source and binary forms, with or without 91.1Scgd * modification, are permitted provided that the following conditions 101.1Scgd * are met: 111.1Scgd * 1. Redistributions of source code must retain the above copyright 121.1Scgd * notice, this list of conditions and the following disclaimer. 131.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 141.1Scgd * notice, this list of conditions and the following disclaimer in the 151.1Scgd * documentation and/or other materials provided with the distribution. 161.1Scgd * 3. All advertising materials mentioning features or use of this software 171.1Scgd * must display the following acknowledgement: 181.1Scgd * This product includes software developed by the University of 191.1Scgd * California, Berkeley and its contributors. 201.1Scgd * 4. Neither the name of the University nor the names of its contributors 211.1Scgd * may be used to endorse or promote products derived from this software 221.1Scgd * without specific prior written permission. 231.1Scgd * 241.1Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341.1Scgd * SUCH DAMAGE. 351.1Scgd */ 361.1Scgd 371.1Scgd#ifndef lint 381.12Smycroftstatic char copyright[] = 391.12Smycroft"@(#) Copyright (c) 1988, 1993\n\ 401.12Smycroft The Regents of the University of California. All rights reserved.\n"; 411.1Scgd#endif /* not lint */ 421.1Scgd 431.1Scgd#ifndef lint 441.12Smycroft/*static char sccsid[] = "from: @(#)slattach.c 8.2 (Berkeley) 1/7/94";*/ 451.13Scgdstatic char *rcsid = "$Id: slattach.c,v 1.13 1994/10/31 04:38:09 cgd Exp $"; 461.1Scgd#endif /* not lint */ 471.1Scgd 481.1Scgd#include <sys/param.h> 491.12Smycroft#include <sys/socket.h> 501.12Smycroft 511.12Smycroft#include <net/if.h> 521.12Smycroft#include <netinet/in.h> 531.12Smycroft 541.12Smycroft#include <err.h> 551.12Smycroft#include <fcntl.h> 561.1Scgd#include <netdb.h> 571.12Smycroft#include <paths.h> 581.1Scgd#include <stdio.h> 591.12Smycroft#include <stdlib.h> 601.13Scgd#include <string.h> 611.12Smycroft#include <termios.h> 621.12Smycroft 631.12Smycroftint speed = 9600; 641.12Smycroftint slipdisc = SLIPDISC; 651.1Scgd 661.12Smycroftchar devicename[32]; 671.1Scgd 681.12Smycroftvoid usage __P((void)); 691.1Scgd 701.12Smycroftint 711.12Smycroftmain(argc, argv) 721.12Smycroft int argc; 731.12Smycroft char *argv[]; 741.1Scgd{ 751.12Smycroft register int fd; 761.12Smycroft register char *dev = argv[1]; 771.4Scgd struct termios tty; 781.12Smycroft tcflag_t cflag = HUPCL; 791.12Smycroft int ch; 801.4Scgd 811.12Smycroft while ((ch = getopt(argc, argv, "hms:")) != -1) { 821.12Smycroft switch (ch) { 831.4Scgd case 'h': 841.12Smycroft cflag |= CRTSCTS; 851.8Smycroft break; 861.8Smycroft case 'm': 871.12Smycroft cflag &= ~HUPCL; 881.4Scgd break; 891.4Scgd case 's': 901.4Scgd speed = atoi(optarg); 911.4Scgd break; 921.4Scgd case '?': 931.4Scgd default: 941.12Smycroft usage(); 951.4Scgd } 961.4Scgd } 971.12Smycroft argc -= optind; 981.12Smycroft argv += optind; 991.4Scgd 1001.12Smycroft if (argc != 1) 1011.12Smycroft usage(); 1021.4Scgd 1031.12Smycroft dev = *argv; 1041.1Scgd if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { 1051.12Smycroft (void)snprintf(devicename, sizeof(devicename), 1061.12Smycroft "%s%s", _PATH_DEV, dev); 1071.12Smycroft dev = devicename; 1081.1Scgd } 1091.1Scgd if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { 1101.1Scgd perror(dev); 1111.1Scgd exit(1); 1121.1Scgd } 1131.12Smycroft tty.c_cflag = CREAD | CS8 | cflag; 1141.4Scgd tty.c_iflag = 0; 1151.12Smycroft tty.c_lflag = 0; 1161.4Scgd tty.c_oflag = 0; 1171.12Smycroft tty.c_cc[VMIN] = 1; 1181.12Smycroft tty.c_cc[VTIME] = 0; 1191.12Smycroft cfsetspeed(&tty, speed); 1201.12Smycroft if (tcsetattr(fd, TCSADRAIN, &tty) < 0) 1211.12Smycroft err(1, "tcsetattr"); 1221.12Smycroft if (ioctl(fd, TIOCSDTR, 0) < 0) 1231.12Smycroft err(1, "TIOCSDTR"); 1241.12Smycroft if (ioctl(fd, TIOCSETD, &slipdisc) < 0) 1251.12Smycroft err(1, "TIOCSETD"); 1261.1Scgd 1271.1Scgd if (fork() > 0) 1281.1Scgd exit(0); 1291.1Scgd for (;;) 1301.1Scgd sigpause(0L); 1311.12Smycroft} 1321.12Smycroft 1331.12Smycroftvoid 1341.12Smycroftusage() 1351.12Smycroft{ 1361.12Smycroft 1371.12Smycroft (void)fprintf(stderr, "usage: slattach [-hm] [-s baudrate] ttyname\n"); 1381.12Smycroft exit(1); 1391.1Scgd} 140