2 * Copyright (c) 2006, Swedish Institute of Computer Science
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * $Id: scat.c,v 1.6 2007/05/21 15:22:45 bg- Exp $
38 #include <sys/types.h>
45 #include <sys/ioctl.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
55 #define SLIP_ESC_END 0334
56 #define SLIP_ESC_ESC 0335
59 #define BAUDRATE B115200
61 speed_t b_rate
= BAUDRATE
;
69 if(tcflush(fd
, TCIOFLUSH
) == -1) err(1, "tcflush");
71 if(tcgetattr(fd
, &tty
) == -1) err(1, "tcgetattr");
78 tty
.c_cflag
&= ~CRTSCTS
;
79 tty
.c_cflag
&= ~HUPCL
;
80 tty
.c_cflag
&= ~CLOCAL
;
82 cfsetispeed(&tty
, b_rate
);
83 cfsetospeed(&tty
, b_rate
);
85 if(tcsetattr(fd
, TCSAFLUSH
, &tty
) == -1) err(1, "tcsetattr");
87 tty
.c_cflag
|= CLOCAL
;
88 if(tcsetattr(fd
, TCSAFLUSH
, &tty
) == -1) err(1, "tcsetattr");
91 if(ioctl(fd
, TIOCMBIS
, &i
) == -1) err(1, "ioctl");
93 usleep(10*1000); /* Wait for hardware 10ms. */
95 /* Flush input and output buffers. */
96 if(tcflush(fd
, TCIOFLUSH
) == -1) err(1, "tcflush");
100 main(int argc
, char **argv
)
108 while ((c
= getopt(argc
, argv
, "B:")) != -1) {
111 baudrate
= atoi(optarg
);
117 err(1, "usage: scat [-B baudrate] device-file");
121 argc
-= (optind
- 1);
122 argv
+= (optind
- 1);
126 break; /* Use default. */
143 err(1, "unknown baudrate %d", baudrate
);
148 err(1, "usage: scat device-file");
151 setvbuf(stdout
, NULL
, _IOLBF
, 0); /* Line buffered output. */
153 slipfd
= open(siodev
, O_RDWR
);
154 if (slipfd
== -1) err(1, "can't open '%s'", siodev
);
156 inslip
= fdopen(slipfd
, "r");
157 if(inslip
== NULL
) err(1, "main: fdopen");
160 int c
= getc(inslip
);
161 while (c
== SLIP_END
)
166 if (c
== SLIP_ESC_ESC
)
168 else if (c
== SLIP_ESC_END
)
173 err(1, "getc(inslip)");
194 } while (c
!= SLIP_END
);