-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopback.pl
More file actions
18 lines (18 loc) · 768 Bytes
/
loopback.pl
File metadata and controls
18 lines (18 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use strict;
use IO::Socket::UNIX qw( SOCK_STREAM );
my $socket_path = "/tmp/artemis.sock";
my $socket = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Peer => $socket_path,
) or die("Can't connect to server: $!\n");
print "Connected!\n";
print $socket pack("CCn/a*",128,1,"chat");
my $buf;
while(defined($socket->recv($buf,4)) && defined($buf)){
my($version, $type, $length) = unpack("CCn",$buf);
next unless $version == 128 && $type == 0;
$socket->recv($buf, $length);
my($id,$type,$sender,$returnpath,$message)=unpack("n C/a C/a n/a a*",$buf);
print "Looping back a '$type' message ('$message') at $sender via $returnpath on gateway $id\n";
print $socket pack("CCn/a*",128,4,pack("n C/a* n/a* a*",$id,$type,$returnpath,$message));
}