146 lines
3.8 KiB
Diff
146 lines
3.8 KiB
Diff
diff -up nmap-6.01/ncat/test/ncat-test.pl.shutdown_test nmap-6.01/ncat/test/ncat-test.pl
|
|
--- nmap-6.01/ncat/test/ncat-test.pl.shutdown_test 2011-12-19 20:12:48.000000000 +0100
|
|
+++ nmap-6.01/ncat/test/ncat-test.pl 2012-11-27 14:18:16.000000000 +0100
|
|
@@ -21,6 +21,8 @@ my $HOST = "localhost";
|
|
my $IPV6_ADDR = "::1";
|
|
my $PORT = 40000;
|
|
my $PROXY_PORT = 40001;
|
|
+my $UNIXSOCK = "ncat.unixsock";
|
|
+my $UNIXSOCK_TMP = "ncat.unixsock_tmp";
|
|
|
|
my $BUFSIZ = 1024;
|
|
|
|
@@ -531,6 +533,22 @@ sub {
|
|
};
|
|
kill_children;
|
|
|
|
+# Test UNIX domain sockets listening
|
|
+($s_pid, $s_out, $s_in) = ncat("-l", "-U", $UNIXSOCK);
|
|
+test "Server UNIX socket listen on $UNIXSOCK (STREAM)",
|
|
+sub {
|
|
+ my $resp;
|
|
+
|
|
+ unlink($UNIXSOCK);
|
|
+ my ($c_pid, $c_out, $c_in) = ncat("-U", $UNIXSOCK);
|
|
+ syswrite($c_in, "abc\n");
|
|
+ $resp = timeout_read($s_out);
|
|
+ $resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\" from client";
|
|
+};
|
|
+kill_children;
|
|
+unlink($UNIXSOCK);
|
|
+
|
|
+
|
|
server_client_test "Connect success exit code",
|
|
[], ["--send-only"], sub {
|
|
my ($pid, $code);
|
|
@@ -655,16 +673,37 @@ sub {
|
|
};
|
|
kill_children;
|
|
|
|
+server_client_test_all "Messages are logged to output file",
|
|
+["--output", "server.log"], ["--output", "client.log"], sub {
|
|
+
|
|
+ syswrite($c_in, "abc\n");
|
|
+ sleep 1;
|
|
+ syswrite($s_in, "def\n");
|
|
+ sleep 1;
|
|
+ close($c_in);
|
|
+ open(FH, "server.log");
|
|
+ my $contents = join("", <FH>);
|
|
+ close(FH);
|
|
+ $contents eq "abc\ndef\n" or die "Server logged " . d($contents);
|
|
+ open(FH, "client.log");
|
|
+ $contents = join("", <FH>);
|
|
+ close(FH);
|
|
+ $contents eq "abc\ndef\n" or die "Client logged " . d($contents);
|
|
+};
|
|
+unlink "server.log";
|
|
+unlink "client.log";
|
|
+kill_children;
|
|
+
|
|
server_client_test_tcp_sctp_ssl "Debug messages go to stderr",
|
|
["-vvv"], ["-vvv"], sub {
|
|
my $resp;
|
|
|
|
syswrite($c_in, "abc\n");
|
|
- close($c_in);
|
|
$resp = timeout_read($s_out) or die "Read timeout";
|
|
$resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\"";
|
|
syswrite($s_in, "abc\n");
|
|
close($s_in);
|
|
+ close($c_in);
|
|
$resp = timeout_read($c_out) or die "Read timeout";
|
|
$resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\"";
|
|
};
|
|
@@ -690,6 +729,36 @@ server_client_test_tcp_sctp_ssl "Server
|
|
};
|
|
kill_children;
|
|
|
|
+server_client_test "Client shutdown()s connection when reading EOF",
|
|
+[], [], sub {
|
|
+ my $resp;
|
|
+
|
|
+ syswrite($c_in, "abc\n");
|
|
+ $resp = timeout_read($s_out) or die "Read timeout";
|
|
+ $resp eq "abc\n" or die "Server got \"$resp\", not \"abc\\n\"";
|
|
+
|
|
+ close($c_in);
|
|
+
|
|
+ $resp = timeout_read($s_out);
|
|
+ !defined($resp) or die "Server didn't get EOF (got \"$resp\")";
|
|
+};
|
|
+kill_children;
|
|
+
|
|
+server_client_test "Server shutdown()s connection when reading EOF",
|
|
+[], [], sub {
|
|
+ my $resp;
|
|
+
|
|
+ syswrite($s_in, "abc\n");
|
|
+ $resp = timeout_read($c_out) or die "Read timeout";
|
|
+ $resp eq "abc\n" or die "Client got \"$resp\", not \"abc\\n\"";
|
|
+
|
|
+ close($s_in);
|
|
+
|
|
+ $resp = timeout_read($c_out);
|
|
+ !defined($resp) or die "Client didn't get EOF (got \"$resp\")";
|
|
+};
|
|
+kill_children;
|
|
+
|
|
# Tests to check that server defaults to non-persistent without --keep-open.
|
|
|
|
# Server immediately quits after the first connection closed without --keep-open
|
|
@@ -1195,6 +1264,33 @@ sub {
|
|
};
|
|
kill_children;
|
|
|
|
+# Test connecting to UNIX datagram socket with -s
|
|
+test "Connect to UNIX datagram socket with -s",
|
|
+sub {
|
|
+ my ($pid, $code);
|
|
+ local $SIG{CHLD} = sub { };
|
|
+ local *SOCK;
|
|
+ my $buff;
|
|
+
|
|
+ unlink($UNIXSOCK);
|
|
+ unlink($UNIXSOCK_TMP);
|
|
+
|
|
+ socket(SOCK, AF_UNIX, SOCK_DGRAM, 0) or die;
|
|
+ bind(SOCK, sockaddr_un($UNIXSOCK)) or die;
|
|
+
|
|
+ my ($c_pid, $c_out, $c_in) = ncat("-U", "--udp", "-s", $UNIXSOCK_TMP, $UNIXSOCK);
|
|
+ syswrite($c_in, "abc\n");
|
|
+ close($c_in);
|
|
+
|
|
+ my $peeraddr = recv(SOCK, $buff, 4, 0) or die;
|
|
+ my ($path) = sockaddr_un($peeraddr);
|
|
+ $path eq $UNIXSOCK_TMP or die "Client connected to prosy with source socket path $path, not $UNIXSOCK_TMP";
|
|
+};
|
|
+kill_children;
|
|
+unlink($UNIXSOCK);
|
|
+unlink($UNIXSOCK_TMP);
|
|
+
|
|
+
|
|
# HTTP proxy tests.
|
|
|
|
sub http_request {
|