]> git.saurik.com Git - apple/network_cmds.git/blame - slattach.tproj/slattach.c
network_cmds-176.3.1.tar.gz
[apple/network_cmds.git] / slattach.tproj / slattach.c
CommitLineData
b7080c8e
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
921c0aec
A
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
b7080c8e
A
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
921c0aec
A
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
b7080c8e
A
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Copyright (c) 1988, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * This code is derived from software contributed to Berkeley by
29 * Rick Adams.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 */
59
60
61#include <sys/param.h>
62#include <sgtty.h>
63#include <sys/socket.h>
64#include <netinet/in.h>
65#include <net/if.h>
66#include <netdb.h>
67#include <fcntl.h>
68#include <stdio.h>
69#include <paths.h>
70
71#define DEFAULT_BAUD 9600
72int slipdisc = SLIPDISC;
73
74__private_extern__
75char devname[32] = { '\0' };
76char hostname[MAXHOSTNAMELEN];
77
78main(argc, argv)
79 int argc;
80 char *argv[];
81{
82 register int fd;
83 register char *dev = argv[1];
84 struct sgttyb sgtty;
85 int speed;
86
87 if (argc < 2 || argc > 3) {
88 fprintf(stderr, "usage: %s ttyname [baudrate]\n", argv[0]);
89 exit(1);
90 }
91 speed = argc == 3 ? findspeed(atoi(argv[2])) : findspeed(DEFAULT_BAUD);
92 if (speed == 0) {
93 fprintf(stderr, "unknown speed %s", argv[2]);
94 exit(1);
95 }
96 if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) {
97 (void)snprintf(devname, sizeof(devname),
98 "%s%s", _PATH_DEV, dev);
99 dev = devname;
100 }
101 if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) {
102 perror(dev);
103 exit(1);
104 }
105 sgtty.sg_flags = RAW | ANYP;
106 sgtty.sg_ispeed = sgtty.sg_ospeed = speed;
107 if (ioctl(fd, TIOCSETP, &sgtty) < 0) {
108 perror("ioctl(TIOCSETP)");
109 exit(1);
110 }
111 if (ioctl(fd, TIOCSETD, &slipdisc) < 0) {
112 perror("ioctl(TIOCSETD)");
113 exit(1);
114 }
115
116 if (fork() > 0)
117 exit(0);
118 for (;;)
119 sigpause(0L);
120}
121
122struct sg_spds {
123 int sp_val, sp_name;
124} spds[] = {
125#ifdef B50
126 { 50, B50 },
127#endif
128#ifdef B75
129 { 75, B75 },
130#endif
131#ifdef B110
132 { 110, B110 },
133#endif
134#ifdef B150
135 { 150, B150 },
136#endif
137#ifdef B200
138 { 200, B200 },
139#endif
140#ifdef B300
141 { 300, B300 },
142#endif
143#ifdef B600
144 { 600, B600 },
145#endif
146#ifdef B1200
147 { 1200, B1200 },
148#endif
149#ifdef B1800
150 { 1800, B1800 },
151#endif
152#ifdef B2000
153 { 2000, B2000 },
154#endif
155#ifdef B2400
156 { 2400, B2400 },
157#endif
158#ifdef B3600
159 { 3600, B3600 },
160#endif
161#ifdef B4800
162 { 4800, B4800 },
163#endif
164#ifdef B7200
165 { 7200, B7200 },
166#endif
167#ifdef B9600
168 { 9600, B9600 },
169#endif
170#ifdef EXTA
171 { 19200, EXTA },
172#endif
173#ifdef EXTB
174 { 38400, EXTB },
175#endif
176 { 0, 0 }
177};
178
179findspeed(speed)
180 register int speed;
181{
182 register struct sg_spds *sp;
183
184 sp = spds;
185 while (sp->sp_val && sp->sp_val != speed)
186 sp++;
187 return (sp->sp_name);
188}