slattach.c revision 1.14
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.14Scgdstatic char *rcsid = "$Id: slattach.c,v 1.14 1994/12/18 00:26:34 cgd Exp $"; 461.1Scgd#endif /* not lint */ 471.1Scgd 481.1Scgd#include <sys/param.h> 491.12Smycroft#include <sys/socket.h> 501.14Scgd#include <sys/types.h> 511.14Scgd#include <sys/ioctl.h> 521.12Smycroft 531.12Smycroft#include <net/if.h> 541.12Smycroft#include <netinet/in.h> 551.12Smycroft 561.12Smycroft#include <err.h> 571.12Smycroft#include <fcntl.h> 581.1Scgd#include <netdb.h> 591.12Smycroft#include <paths.h> 601.14Scgd#include <signal.h> 611.1Scgd#include <stdio.h> 621.12Smycroft#include <stdlib.h> 631.13Scgd#include <string.h> 641.12Smycroft#include <termios.h> 651.14Scgd#include <unistd.h> 661.12Smycroft 671.12Smycroftint speed = 9600; 681.12Smycroftint slipdisc = SLIPDISC; 691.1Scgd 701.12Smycroftchar devicename[32]; 711.1Scgd 721.12Smycroftvoid usage __P((void)); 731.1Scgd 741.12Smycroftint 751.12Smycroftmain(argc, argv) 761.12Smycroft int argc; 771.12Smycroft char *argv[]; 781.1Scgd{ 791.12Smycroft register int fd; 801.12Smycroft register char *dev = argv[1]; 811.4Scgd struct termios tty; 821.12Smycroft tcflag_t cflag = HUPCL; 831.12Smycroft int ch; 841.4Scgd 851.12Smycroft while ((ch = getopt(argc, argv, "hms:")) != -1) { 861.12Smycroft switch (ch) { 871.4Scgd case 'h': 881.12Smycroft cflag |= CRTSCTS; 891.8Smycroft break; 901.8Smycroft case 'm': 911.12Smycroft cflag &= ~HUPCL; 921.4Scgd break; 931.4Scgd case 's': 941.4Scgd speed = atoi(optarg); 951.4Scgd break; 961.4Scgd case '?': 971.4Scgd default: 981.12Smycroft usage(); 991.4Scgd } 1001.4Scgd } 1011.12Smycroft argc -= optind; 1021.12Smycroft argv += optind; 1031.4Scgd 1041.12Smycroft if (argc != 1) 1051.12Smycroft usage(); 1061.4Scgd 1071.12Smycroft dev = *argv; 1081.1Scgd if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { 1091.12Smycroft (void)snprintf(devicename, sizeof(devicename), 1101.12Smycroft "%s%s", _PATH_DEV, dev); 1111.12Smycroft dev = devicename; 1121.1Scgd } 1131.1Scgd if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) { 1141.1Scgd perror(dev); 1151.1Scgd exit(1); 1161.1Scgd } 1171.12Smycroft tty.c_cflag = CREAD | CS8 | cflag; 1181.4Scgd tty.c_iflag = 0; 1191.12Smycroft tty.c_lflag = 0; 1201.4Scgd tty.c_oflag = 0; 1211.12Smycroft tty.c_cc[VMIN] = 1; 1221.12Smycroft tty.c_cc[VTIME] = 0; 1231.12Smycroft cfsetspeed(&tty, speed); 1241.12Smycroft if (tcsetattr(fd, TCSADRAIN, &tty) < 0) 1251.12Smycroft err(1, "tcsetattr"); 1261.12Smycroft if (ioctl(fd, TIOCSDTR, 0) < 0) 1271.12Smycroft err(1, "TIOCSDTR"); 1281.12Smycroft if (ioctl(fd, TIOCSETD, &slipdisc) < 0) 1291.12Smycroft err(1, "TIOCSETD"); 1301.1Scgd 1311.1Scgd if (fork() > 0) 1321.1Scgd exit(0); 1331.1Scgd for (;;) 1341.1Scgd sigpause(0L); 1351.12Smycroft} 1361.12Smycroft 1371.12Smycroftvoid 1381.12Smycroftusage() 1391.12Smycroft{ 1401.12Smycroft 1411.12Smycroft (void)fprintf(stderr, "usage: slattach [-hm] [-s baudrate] ttyname\n"); 1421.12Smycroft exit(1); 1431.1Scgd} 144