title: Using socat to relay one TTY stream to multiple TCP/IP destinations, plus to one 'sniffer' program
body: <p>Using an embedded Linux development board, I need to put together a widget that does the following:</p>
  
  <ul>
  <li>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).</li>
  <li>Also 'sniff' those serial packets using a custom program, perhaps written in <code>c</code>.</li>
  </ul>
  
  <p>As someone with a programming background, the most obvious solution (to me) would be to create a <code>c</code> 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 <code>sniffer.c</code>).  </p>
  
  <p>I understand that <code>netcat</code> and <code>socat</code> 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 <code>socat</code> to relay serial data from the TTY port to remote IP addresses. Each instance of <code>socat</code> could handle a particular remote IP address.</p>
  
  <p>Does this sound feasible, and if so, how could I effectively 'multiplex' a stream from <code>/dev/ttyS0</code> (say) as the source for multiple instances of <code>socat</code> plus one instance of <code>sniffer.c</code>? Could one way be to relay data read from <code>/dev/ttyS0</code> to a cache file, and then have my <code>socat</code> instances and <code>sniffer.c</code> all have a read-only access to that file?</p>