my $srcdir = $ENV{'srcdir'} || '.';
my $HOSTIP="127.0.0.1";
+my $HOST6IP="[::1]";
my $base = 8990; # base port number
my $HTTPPORT; # HTTP server port
+my $HTTP6PORT; # HTTP IPv6 server port
my $HTTPSPORT; # HTTPS server port
my $FTPPORT; # FTP server port
my $FTPSPORT; # FTPS server port
#
my $HTTPPIDFILE=".http.pid";
+my $HTTP6PIDFILE=".http6.pid";
my $HTTPSPIDFILE=".https.pid";
my $FTPPIDFILE=".ftp.pid";
my $FTPSPIDFILE=".ftps.pid";
my $ssl_version; # set if libcurl is built with SSL support
my $large_file; # set if libcurl is built with large file support
my $has_idn; # set if libcurl is built with IDN support
+my $http_ipv6; # set if HTTP server has IPv6 support
my $has_ipv6; # set if libcurl is built with IPv6 support
my $has_libz; # set if libcurl is built with libz support
my $has_getrlimit; # set if system has getrlimit()
# test server on the test-port!
#
sub runhttpserver {
- my $verbose = $_[0];
+ my ($verbose, $ipv6) = @_;
my $RUNNING;
my $pid;
- $pid = checkserver ($HTTPPIDFILE);
+ my $pidfile = $HTTPPIDFILE;
+ my $port = $HTTPPORT;
+ my $ip = $HOSTIP;
+ my $nameext;
+
+ if($ipv6) {
+ # if IPv6, use a different setup
+ $pidfile = $HTTP6PIDFILE;
+ $port = $HTTP6PORT;
+ $ip = $HOST6IP;
+ $nameext="-ipv6";
+ }
+
+
+ $pid = checkserver($pidfile);
# verify if our/any server is running on this port
- my $cmd = "$CURL -o log/verifiedserver http://$HOSTIP:$HTTPPORT/verifiedserver 2>/dev/null";
+ my $cmd = "$CURL -o log/verifiedserver -g \"http://$ip:$port/verifiedserver\" 2>/dev/null";
print "CMD; $cmd\n" if ($verbose);
my $res = system($cmd);
$pid = 0+$1;
}
elsif($data || ($res != 7)) {
- print "RUN: Unknown HTTP server is running on port $HTTPPORT\n";
+ print "RUN: Unknown server is running on port $port\n";
return -2;
}
if($pid > 0) {
my $res = kill (9, $pid); # die!
if(!$res) {
- print "RUN: Failed to kill test HTTP server, do it manually and",
- " restart the tests.\n";
+ print "RUN: Failed to kill test HTTP$nameext server, do it ",
+ "manually and restart the tests.\n";
exit;
}
sleep(1);
if($dir) {
$flag .= "-d \"$dir\" ";
}
- $cmd="$perl $srcdir/httpserver.pl $flag $HTTPPORT &";
+ $cmd="$perl $srcdir/httpserver.pl $flag $port $ipv6 &";
system($cmd);
if($verbose) {
print "CMD: $cmd\n";
my $verified;
for(1 .. 10) {
# verify that our server is up and running:
- my $data=`$CURL --silent $HOSTIP:$HTTPPORT/verifiedserver 2>/dev/null`;
+ my $data=`$CURL --silent -g \"$ip:$port/verifiedserver\" 2>/dev/null`;
if ( $data =~ /WE ROOLZ: (\d+)/ ) {
$pid = 0+$1;
}
else {
if($verbose) {
- print STDERR "RUN: Retrying HTTP server existence in 3 sec\n";
+ print STDERR "RUN: Retrying HTTP$nameext server existence in 3 sec\n";
}
sleep(3);
next;
}
}
if(!$verified) {
- print STDERR "RUN: failed to start our HTTP server\n";
+ print STDERR "RUN: failed to start our HTTP$nameext server\n";
return -1;
}
if($verbose) {
- print "RUN: HTTP server is now verified to be our server\n";
+ print "RUN: HTTP$nameext server is now verified to be our server\n";
}
return $pid;
close(CONF);
}
+ if($has_ipv6) {
+ # client has ipv6 support, check that the HTTP server has it!
+ my @sws = `server/sws --version`;
+ if($sws[0] =~ /IPv6/) {
+ # HTTP server has ipv6 support!
+ $http_ipv6 = 1;
+ }
+ }
+
if(!$curl_debug && $torture) {
die "can't run torture tests since curl was not build with debug";
}
"* Host: $hostname",
"* System: $hosttype";
- printf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
- printf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
- printf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
- printf("* valgrind: %s\n", $valgrind?"ON":"OFF");
- printf("* HTTP on port: %d\n", $HTTPPORT);
- printf("* FTP on port: %d\n", $FTPPORT);
+ printf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
+ printf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
+ printf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
+ printf("* valgrind: %s\n", $valgrind?"ON":"OFF");
+ printf("* HTTP IPv6 %s\n", $http_ipv6?"ON":"OFF");
+
+ printf("* HTTP port: %d\n", $HTTPPORT);
+ printf("* FTP port: %d\n", $FTPPORT);
if($stunnel) {
- printf("* FTPS on port: %d\n", $FTPSPORT);
- printf("* HTTPS on port: %d\n", $HTTPSPORT);
+ printf("* FTPS port: %d\n", $FTPSPORT);
+ printf("* HTTPS port: %d\n", $HTTPSPORT);
+ }
+ if($http_ipv6) {
+ printf("* HTTP IPv6 port: %d\n", $HTTP6PORT);
}
print "***************************************** \n";
}
my ($thing) = @_;
$$thing =~ s/%HOSTIP/$HOSTIP/g;
$$thing =~ s/%HTTPPORT/$HTTPPORT/g;
+ $$thing =~ s/%HOST6IP/$HOST6IP/g;
+ $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
$$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
$$thing =~ s/%FTPPORT/$FTPPORT/g;
$$thing =~ s/%FTPSPORT/$FTPSPORT/g;
}
if($valgrind) {
- $CMDLINE = "valgrind ".$valgrind_tool."--leak-check=yes --logfile=log/valgrind$testnum -q $CMDLINE";
+ $CMDLINE = "valgrind ".$valgrind_tool."--leak-check=yes --logfile=log/valgrind$testnum $CMDLINE";
}
$CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
my $pid;
for(@what) {
my $what = lc($_);
- $what =~ s/[^a-z]//g;
+ $what =~ s/[^a-z0-9-]//g;
if($what eq "ftp") {
if(!$run{'ftp'}) {
$pid = runftpserver($verbose);
$run{'http'}=$pid;
}
}
+ elsif($what eq "http-ipv6") {
+ if(!$run{'http-ipv6'}) {
+ $pid = runhttpserver($verbose, "IPv6");
+ if($pid <= 0) {
+ return 2; # error starting
+ }
+ printf ("* pid http-ipv6 => %-5d\n", $pid) if($verbose);
+ $run{'http-ipv6'}=$pid;
+ }
+ }
elsif($what eq "ftps") {
if(!$stunnel || !$ssl_version) {
# we can't run ftps tests without stunnel
$HTTPSPORT = $base + 1; # HTTPS server port
$FTPPORT = $base + 2; # FTP server port
$FTPSPORT = $base + 3; # FTPS server port
+$HTTP6PORT = $base + 4; # HTTP IPv6 server port (different IP protocol
+ # but we follow the same port scheme anyway)
#######################################################################
# Output curl version and host info being tested
#include "curlx.h" /* from the private lib dir */
#include "getpart.h"
+#ifdef ENABLE_IPV6
+#define SWS_IPV6
+#endif
+
#ifndef FALSE
#define FALSE 0
#endif
}
#endif
+char use_ipv6=FALSE;
+
int main(int argc, char *argv[])
{
struct sockaddr_in me;
+#ifdef ENABLE_IPV6
+ struct sockaddr_in6 me6;
+#endif /* ENABLE_IPV6 */
int sock, msgsock, flag;
unsigned short port = DEFAULT_PORT;
FILE *pidfile;
struct httprequest req;
+ int rc;
if(argc>1) {
- port = (unsigned short)atoi(argv[1]);
+ int arg=1;
+ if(!strcmp("--version", argv[arg])) {
+ printf("sws IPv4%s\n",
+#ifdef ENABLE_IPV6
+ "/IPv6"
+#else
+ ""
+#endif
+ );
+ return 0;
+ }
+ if(!strcmp("--ipv6", argv[arg])) {
+#ifdef ENABLE_IPV6
+ use_ipv6=TRUE;
+#endif
+ arg++;
+ }
+ if(argc>arg) {
+
+ if(atoi(argv[arg]))
+ port = (unsigned short)atoi(argv[arg++]);
+
+ if(argc>arg)
+ path = argv[arg];
- if(argc>2) {
- path = argv[2];
}
}
#endif
#endif
- sock = socket(AF_INET, SOCK_STREAM, 0);
+#ifdef ENABLE_IPV6
+ if(!use_ipv6)
+#endif
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+#ifdef ENABLE_IPV6
+ else
+ sock = socket(AF_INET6, SOCK_STREAM, 0);
+#endif
+
if (sock < 0) {
perror("opening stream socket");
- logmsg("Error opening socket -- aborting\n");
+ logmsg("Error opening socket");
exit(1);
}
perror("setsockopt(SO_REUSEADDR)");
}
- me.sin_family = AF_INET;
- me.sin_addr.s_addr = INADDR_ANY;
- me.sin_port = htons(port);
- if (bind(sock, (struct sockaddr *) &me, sizeof me) < 0) {
+#ifdef ENABLE_IPV6
+ if(!use_ipv6) {
+#endif
+ me.sin_family = AF_INET;
+ me.sin_addr.s_addr = INADDR_ANY;
+ me.sin_port = htons(port);
+ rc = bind(sock, (struct sockaddr *) &me, sizeof(me));
+#ifdef ENABLE_IPV6
+ }
+ else {
+ memset(&me6, 0, sizeof(struct sockaddr_in6));
+ me6.sin6_family = AF_INET6;
+ me6.sin6_addr = in6addr_any;
+ me6.sin6_port = htons(port);
+ rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6));
+ }
+#endif /* ENABLE_IPV6 */
+ if(rc < 0) {
perror("binding stream socket");
- logmsg("Error binding socket -- aborting\n");
+ logmsg("Error binding socket");
exit(1);
}
else
fprintf(stderr, "Couldn't write pid file\n");
+ logmsg("Running IPv%d version",
+#ifdef ENABLE_IPV6
+ (use_ipv6?6:4)
+#else
+ 4
+#endif
+ );
+
/* start accepting connections */
listen(sock, 5);