Julien Vehent on 20 Dec 2010 11:14:31 -0800

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Named pipes

On 12/20/2010 12:40 AM, Randall A Sindlinger wrote:
On Sun, Dec 19, 2010 at 08:54:55PM -0500, Eric at Lucii.org wrote:
echo "test">  program-named-pipe

As a socket, you should be able to see it with netstat.  You should be
able to write to it via telnet to the port on localhost, assuming that
netstat shows it's listening there and your firewall rules allow it.

AFAIK, Unix socket won't show in netstat until they are connected (the kernel is simply not aware of their existence).

Also, unix sockets are not network socket. Netcat (or telnet) won't connect to it. But socat will. To connect to a unix socket with socat, use 'socat - unix:/path/to/socket'. (the first argument - tells socat to connect stdin and stdout to the socket... yes you can use socat to connect sockets of different types together).

You can create a unix socket with a few lines of Perl (see attached) and experiment.

1. Launch the script

	$ perl socksrv.pl

2. try to list the socket using 'netstat --unix |grep /tmp/testsock' (you won't see anything)

	$ netstat --unix|grep /tmp/testsock

3. connect to the socket using socat

	$ socat -v - unix:/tmp/testsock

4. retry the same netstat as before, this time you see the connection

	$ netstat --unix|grep /tmp/testsock
	unix  3      [ ]         STREAM     CONNECTED     33091    	/tmp/testsock

#!/usr/bin/perl -w
# just launch this with "perl ./socksrv.pl"
# it receives on message from any client and close the connection
use Socket;
use IO::Handle;

unlink "/tmp/testsock";
bind(SERV,sockaddr_un("/tmp/testsock")) or print "ERROR!";

while (accept(CLIENT,SERV)) {
        print "received : ".$datagram;
        print CLIENT "thanks. closing connection\n";
        close CLIENT;
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug