aboutsummaryrefslogtreecommitdiffstats
path: root/tools/node_modules/expresso/deps/jscoverage/tests/netcat.pl
blob: 5df75bee48a55e2e2ec8d574ee7e35b17d897ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use strict;
use warnings;

use Socket;

binmode(STDIN);
$| = 1;
binmode(STDOUT);

if (@ARGV != 2) {
  die "Usage: netcat.pl HOST PORT\n";
}

my $host = shift;
my $port = shift;

my $address = inet_aton($host) or die;
my $address_and_port = sockaddr_in($port, $address);
my $protocol = getprotobyname('tcp');
socket(SOCKET, PF_INET, SOCK_STREAM, $protocol) or die;

my $old = select(SOCKET);
$| = 1;
select($old);
binmode(SOCKET);

connect(SOCKET, $address_and_port) or die;
while (<STDIN>) {
  print SOCKET $_;
}
while (<SOCKET>) {
  print;
}
close(SOCKET);
exit 0;