I have a “sharing” issue with socat
I’d like to overcome.
The issue is simply that all the client communications with the server are private, all the responses from the server are public, going to all clients; I’d like to have a way where server sends private messages to individual clients.
The documentation states under “FORK option group” that:
pipes Creates a pair of unnamed pipes for interprocess communication instead of a socket pair.
OK, GREAT! That got me looking around and I found sockets: How do I use these – either the unnamed pipes OR the sockets?
Of course, if one looks to /proc/-pid-/fd, like this, one gets some interesting information – this is where I found the sockets; I just don’t know how to use this data:
# ls -lh /proc/2743829/fd
total 0
lrwx------ 1 root root 64 Jul 12 08:47 0 -> /dev/pts/7
lrwx------ 1 root root 64 Jul 12 08:47 1 -> /dev/pts/7
lrwx------ 1 root root 64 Jul 12 08:47 2 -> /dev/pts/7
lrwx------ 1 root root 64 Jul 12 08:47 3 -> 'socket:[898046197]'
lrwx------ 1 root root 64 Jul 12 08:47 4 -> 'socket:[898046198]'
lrwx------ 1 root root 64 Jul 12 08:47 5 -> 'socket:[898046199]'
By starting a server, connecting a client, and looking at the two processes that result it’s clear that these sockets
are not inherited or cloned – or, at least, they all have unique numbers between the brackets. Therefore one would surmise that communicating directly with them would work; it’s rather easy to prove with echo
and >
that the normal stdin
, stdout
, and stderr
fd
entries work this way.
Of course there’s the additional issue of figuring out which client is which fork, but if there can be a private dialogue, that’s not so hard.
Note that I would have asked this question differently, focused on the “how can I just butt-in and talk on a child process’s socket?” but I figure that I’m fairly new to socat
and maybe “I’m just doin’ it wrong!”
Additionally, for now I’m just using bash to have this dialogue.
As an aside, if I try and look at the fdinfo
, I don’t find anything useful:
ls -lh /proc/2743829/fdinfo/
total 0
-r--r--r-- 1 root root 0 Jul 12 08:50 0
-r--r--r-- 1 root root 0 Jul 12 08:50 1
-r--r--r-- 1 root root 0 Jul 12 08:50 2
-r--r--r-- 1 root root 0 Jul 12 08:50 3
-r--r--r-- 1 root root 0 Jul 12 08:50 4
-r--r--r-- 1 root root 0 Jul 12 08:50 5
A closing thought: if using socat
‘s tls
capabilities made this easier, I’d gladly go that route.