Multicasting (and broadcasting which is also discussed in this article) provides a means to direct a single packet to more than one host. Special addresses are defined for this purpose and are handled specially by network adapters, networking hardware, and IP stacks.
IPv4 specifications provide broadcasting and multicasting; IPv6 provides multicasting but replaces broadcasting by special multicast modes. UNIX domain sockets do not know broadcasting or multicasting.
The following examples use UDP/IPv4 only. However, they can easily be adapted for raw IPv4 sockets. IPv6 multicasting has not yet been successfully used with socat; please contact the author if you have positive experiences or ideas that go beyond IPV6_ADD_MEMBERSHIP.
All multicast examples presented in this document use multicast address 224.1.0.1; it can be replaced by any valid IPv4 multicast address (except all-systems).
We assume a local network with address 192.168.10.0 and mask 255.255.255.0; an eventual "client" has 192.168.10.1, example "server" and example peer have 192.168.10.2 in all examples. Change these addresses and mask to your own requirements.
All the following examples work bidirectionally except when otherwise noticed. For "clients" we just use STDIO, and for "servers" we use EXEC:hostname which ingores its input but shows us which host the reply comes from. Replace these socat addresses with what is appropriate for your needs (e.g. shell script invocations). Port 6666 can be replaced with any other port (but for ports < 1024 root privilege might be required).
Different kinds of broadcast addresses exist: 255.255.255.255 is local network only; for the IPv4 network 192.168.10.0/24 the "official" broadcast address is 192.168.10.255; the network address 192.168.10.0 is also interpreted as broadcast by some hosts. The two latter forms are routed by gateways. In the following examples we only use broadcast address 192.168.10.255.
This example builds something like a "supervisor" or "client" that communicates with a set of "servers". The supervisor may send packets to the multicast address, and the servers may send response packets. Note that the servers would also respond to other clients' requests.
Multicast server:
socat UDP4-RECVFROM:6666,ip-add-membership=224.1.0.1:192.168.10.2,fork EXEC:hostnameThis command receives multicast packets addressed to 224.1.0.1 and forks a child process for each. The child processes may each send one or more reply packets back to the particular sender. 192.168.10.2 means the address of the interface where multicasts should be received. Run this command on a number of hosts, and they will all respond in parallel.
Multicast client:
socat STDIO UDP4-DATAGRAM:224.1.0.1:6666,range=192.168.10.0/24This process transfers data from stdin to the multicast address, and transfers packets received from the local network to stdout. It does not matter in which direction the first data is passed. A packet from the network is accepted by the IP stack for our socket if:
Broadcast server:
socat UDP4-RECVFROM:6666,broadcast,fork EXEC:hostnameThis command receives packets addressed to a local broadcast address and forks a child process for each. The child processes may each send one or more reply packets back to the particular sender. Run this command on a number of hosts, and they will all respond in parallel.
Broadcast client:
socat STDIO UDP4-DATAGRAM:192.168.10.255:6666,broadcast,range=192.168.10.0/24This process transfers data from stdin to the broadcast address, and transfers packets received from the local network to stdout. It does not matter in which direction the first data is passed. A packet from the network is accepted by the IP stack for our socket if:
The broadcast option is only required for sending or receiving local broadcasts.
It is possible to combine multicast sender and receiver in one socat address. This allows to start processes on different hosts on the local network that will communicate symmetrically, so each process can send messages that are received by all the other ones.
socat STDIO UDP4-DATAGRAM:224.1.0.1:6666,bind=:6666,range=192.168.10.0/24,ip-add-membership=224.1.0.1:192.168.10.2This command is valid for host 192.168.10.2; adapt this address to the particular interface addresses of the hosts.
Starting this process opens a socket on port 6666 that will receive packets directed to multicast address 224.1.0.1. Only packets with matching source address and source port 6666 will be handled though. When this process sends data to the network the packets will be addressed to 224.1.0.1:6666 and have a source address of 192.168.10.2:6666, matching the accept criteria of the peers on the local network.
Note: this command receives the packets it just has sent; add option ip-multicast-loop=0 if this in undesired.
Just as with multicast, it is possible to combine broadcast sender and receiver in one socat address.
socat STDIO UDP4-DATAGRAM:255.255.255.255:6666,bind=:6666,range=192.168.10.0/24,broadcastStarting this process opens a socket on port 6666 that will receive packets directed to a local broadcast addresses. Only packets with matching source address and source port 6666 will be handled though. When this process sends data to the network the packets will be addressed to 255.255.255.255:6666 and have a source address of 192.168.10.2:6666, matching the accept criteria of the peers on the local network.
Note: this command receives the packets it just has sent; there does not seem to exist a simple way to prevent this.
If you do not get an error message during operation, but the packets do not
reach the target processes, use tcpdump to see if the packets have the
correct source and destination addresses and ports, and if they leave and enter
the hosts a ./usr/share/doc/socat/FAQ 0000644 0000000 0000000 00000007517 11065774440 014056 0 ustar root root
Q: What is the clue of socat?
A: socat probably doesn't have any clue. It is more an attempt to smoothly
integrate similar I/O features that are usually handled differently under
UNIX.
Q: What does the prefix XIO mean?
A: XIO means "extended input/output". It is a library/API that provides a
common way for handling files, sockets and other forms of I/O. Its advantage is
that the application may reduce its I/O to open / read+write / close calls,
while the user controls all I/O details (and even basic process properties) by
packing options into the filename string. This is the basic part of socat.
Q: Is there a Windows port of socat available?
A: Try with Cygwin from http://www.cygwin.com/, or upgrade to Linux.
Q: I succeeded to configure and make socat, but ./test.sh says something
like:
./test.sh: No such file or directory
A: You need a bash shell, and its location must be correctly specified in the
first line of test.sh, e.g. /usr/local/bin/bash instead of /bin/bash.
Q: configure disables readline / openssl / libwrap support because it does not
find an include file / the library. How can I tell configure where these files
are?
A: For include locations, use the environment variable CPPFLAGS, for library
locations use LIBS, e.g.:
export CPPFLAGS="-I/home/user/ssl/include"
export LIBS="-L/home/user/ssl/lib"
On some systems (SunOS), you might also need to set LD_LIBRARY_PATH:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/user/ssl/lib"
Then try again:
make distclean; ./configure; make
Q: I succeeded to make socat, but the test.sh script fails for many tests.
Is my socat build corrupt?
A: Probably your socat program is ok; the tests have been developed on Linux
2.4, and there they usually succeed.
But the following OS differences result in errors on non Linux systems:
* Linux allows to bind a socket to any address of range 127.0.0.0/8, not
only 127.0.0.1. Some tests are built on this feature, but they might fail on
other systems.
* Your OS might have no IP6 implementation
* MacOS X has some difficulties, e.g. distinguishing sockets and pipes.
* the OpenSSL tests require OpenSSL support by socat, must have openssl in
$PATH, and "openssl s_server ..." needs enough entropy to generate a key.
Q: When I specify a dual address (two partial addresses linked with "!!") on
the command line, I get some message "event not found", and my shell history
has the line truncated. Not even protecting the '!'s with '\' helps.
A: '!' is appearently used by your shell as history expansion character. Say
"set +H" and add this line to your (bash) profile.
Q: On Solaris, socat was built successfully, but when started, it gets killed
with something like "ld.so.1: ./socat: fatal: libreadline.so.4: open failed: no
such file or directory"
A: The configure script finds your libreadline, but the runtime loader
doesn't. Add the directory where the library resides to your LD_LIBRARY_PATH
variable, e.g.:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sfw/lib/
make distclean; ./configure; make
Q: On Solaris, socat was built successfully, but when started, an assertion
fails: "xioinitialize.c:25: failed assertion `3 << opt_crdly.arg3 == CRDLY'
A: Probably, in a second attempt you set the correct LD_LIBARY_PATH for socat,
but it had not been set during the ./configure run, or you did not "make clean"
before running configure. Try it again:
make distclean; ./configure; make
Q: A socat process, run in background from an interactive shell, is always
stopped with all its child processes after about 5 minutes. killall -9 socat is
required to clean the system and allow socat to be started again.
A: The terminal (window) might have the TOSTOP flag set and one of the socat
processes wants to write to the terminal. Clear this flag in your shell:
stty -tostop
and start socat again.
Thanks to Philippe Teuwen for reporting this situation.
./usr/share/doc/socat/changelog.Debian.gz 0000644 0000000 0000000 00000004611 11753275265 017173 0 ustar root root Y]w6}9Z[Dq=M$M7}byHHD̯%H+@J%ٖCbY&ẁx
;qTj.hXzTÌ˼LìJyKZ@,HK|8*JŽH.`rT
d bLc`PBe8ˢpو$yRf['J;E5 ]%πRK`2`,F!GyJ={x "t)TSEG+\tO_s\*#cN_TyxIB ԉR77%&