Using an embedded Linux development board, I need to put together a widget that does the following:
- Reads packets in via physical serial port, and relays those packets to a number of IP addresses (up to 20 of them; with IP destinations read from a configuration file).
- Also 'sniff' those serial packets using a custom program, perhaps written in
c
.
As someone with a programming background, the most obvious solution (to me) would be to create a c
program from scratch to achieve the above. However, as this is something I need to throw together quickly, and because I need an excuse to learn more about existing Linux command-line programs and script writing (which I'm not so good at), I'm wondering if much of this could be achieved with existing command-line programs and a shell script. Then, the only part I write from scratch is my packet sniffer (call it sniffer.c
).
I understand that netcat
and socat
can be used for relaying between devices and addresses, and I have started experimenting with both. The thought occurs to me that I could avoid having to develop and test TCP/IP software by running multiple instances of socat
to relay serial data from the TTY port to remote IP addresses. Each instance of socat
could handle a particular remote IP address.
Does this sound feasible, and if so, how could I effectively 'multiplex' a stream from /dev/ttyS0
(say) as the source for multiple instances of socat
plus one instance of sniffer.c
? Could one way be to relay data read from /dev/ttyS0
to a cache file, and then have my socat
instances and sniffer.c
all have a read-only access to that file?