Is it possible on Linux for a process to write inside a socket open by another one?
Let's say I open a connection to google.com using netcat:
myuser@linux:~$ nc google.com 80
Now I can lookup for the process pid and open its file descriptor folder:
myuser@linux:~$ ls -la /proc/24105/fd
totale 0
dr-x------ 2 myuser myuser 0 2012-03-10 19:01 .
dr-xr-xr-x 7 myuser myuser 0 2012-03-10 19:01 ..
lrwx------ 1 myuser myuser 64 2012-03-10 19:02 0 -> /dev/pts/12
lrwx------ 1 myuser myuser 64 2012-03-10 19:02 1 -> /dev/pts/12
lrwx------ 1 myuser myuser 64 2012-03-10 19:01 2 -> /dev/pts/12
lrwx------ 1 myuser myuser 64 2012-03-10 19:02 3 -> socket:[3947162]
So now I would like to make the HTTP request using an echo inside that socket:
myuser@linux:~$ echo "GET / HTTP/1.1" >> /proc/24285/fd/3
bash: /proc/24285/fd/3: no such device or address
Doing it as root doesn't change the result.
I can't write inside the socket but I can write inside the stdin:
myuser@linux:~$ echo "GET / HTTP/1.1" >> /proc/24285/fd/0
myuser@linux:~$
But it's not what I want to do.
I was thinking: a Linux socket should be treated like a file, isn't it? One or more processes can use the same socket, so why can't I do this?