|
|
1.1 root 1: /*
2: * Copyright (c) 1988 Regents of the University of California.
3: * 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 are permitted
9: * provided that the above copyright notice and this paragraph are
10: * duplicated in all such forms and that any documentation,
11: * advertising materials, and other materials related to such
12: * distribution and use acknowledge that the software was developed
13: * by the University of California, Berkeley. The name of the
14: * University may not be used to endorse or promote products derived
15: * from this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: */
20:
21: #ifndef lint
22: char copyright[] =
23: "@(#) Copyright (c) 1988 Regents of the University of California.\n\
24: All rights reserved.\n";
25: #endif /* not lint */
26:
27: #ifndef lint
28: static char sccsid[] = "@(#)slattach.c 4.3 (Berkeley) 6/30/88";
29: #endif /* not lint */
30:
31: #include <stdio.h>
32: #include <sys/param.h>
33: #include <sgtty.h>
34: #include <sys/socket.h>
35: #include <netinet/in.h>
36: #include <net/if.h>
37: #include <netdb.h>
38: #include <fcntl.h>
39:
40: #define DEFAULT_BAUD 9600
41: int slipdisc = SLIPDISC;
42:
43: char devname[32];
44: char hostname[MAXHOSTNAMELEN];
45:
46: main(argc, argv)
47: int argc;
48: char *argv[];
49: {
50: register int fd;
51: register char *dev = argv[1];
52: struct sgttyb sgtty;
53: int speed;
54:
55: if (argc < 2 || argc > 3) {
56: fprintf(stderr, "usage: %s ttyname [baudrate]\n", argv[0]);
57: exit(1);
58: }
59: speed = argc == 3 ? findspeed(atoi(argv[2])) : findspeed(DEFAULT_BAUD);
60: if (speed == 0) {
61: fprintf(stderr, "unknown speed %s", argv[2]);
62: exit(1);
63: }
64: if (strncmp("/dev/", dev, 5)) {
65: (void)sprintf(devname, "/dev/%s", dev);
66: dev = devname;
67: }
68: if ((fd = open(dev, O_RDWR | O_NDELAY)) < 0) {
69: perror(dev);
70: exit(1);
71: }
72: sgtty.sg_flags = RAW | ANYP;
73: sgtty.sg_ispeed = sgtty.sg_ospeed = speed;
74: if (ioctl(fd, TIOCSETP, &sgtty) < 0) {
75: perror("ioctl(TIOCSETP)");
76: exit(1);
77: }
78: if (ioctl(fd, TIOCSETD, &slipdisc) < 0) {
79: perror("ioctl(TIOCSETD)");
80: exit(1);
81: }
82:
83: if (fork() > 0)
84: exit(0);
85: for (;;)
86: sigpause(0L);
87: }
88:
89: struct sg_spds {
90: int sp_val, sp_name;
91: } spds[] = {
92: #ifdef B50
93: { 50, B50 },
94: #endif
95: #ifdef B75
96: { 75, B75 },
97: #endif
98: #ifdef B110
99: { 110, B110 },
100: #endif
101: #ifdef B150
102: { 150, B150 },
103: #endif
104: #ifdef B200
105: { 200, B200 },
106: #endif
107: #ifdef B300
108: { 300, B300 },
109: #endif
110: #ifdef B600
111: { 600, B600 },
112: #endif
113: #ifdef B1200
114: { 1200, B1200 },
115: #endif
116: #ifdef B1800
117: { 1800, B1800 },
118: #endif
119: #ifdef B2000
120: { 2000, B2000 },
121: #endif
122: #ifdef B2400
123: { 2400, B2400 },
124: #endif
125: #ifdef B3600
126: { 3600, B3600 },
127: #endif
128: #ifdef B4800
129: { 4800, B4800 },
130: #endif
131: #ifdef B7200
132: { 7200, B7200 },
133: #endif
134: #ifdef B9600
135: { 9600, B9600 },
136: #endif
137: #ifdef EXTA
138: { 19200, EXTA },
139: #endif
140: #ifdef EXTB
141: { 38400, EXTB },
142: #endif
143: { 0, 0 }
144: };
145:
146: findspeed(speed)
147: register int speed;
148: {
149: register struct sg_spds *sp;
150:
151: sp = spds;
152: while (sp->sp_val && sp->sp_val != speed)
153: sp++;
154: return (sp->sp_name);
155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.