aboutsummaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-12-11 21:41:00 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-12-11 21:41:00 +0000
commit9b3b7ad22ea6d677e2e50f3a7d1c41214b49ae29 (patch)
treec73a2d417536cbaff96a99369fe7f063f8db90e2 /tests/server
parent1b8ac7c6b5c95a74ea49b2aa6d4b4650c401e95e (diff)
HTTP IPv6 support added to the test suite
Diffstat (limited to 'tests/server')
-rw-r--r--tests/server/sws.c81
1 files changed, 71 insertions, 10 deletions
diff --git a/tests/server/sws.c b/tests/server/sws.c
index 8503cf2fb..269d0806c 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -58,6 +58,10 @@
#include "curlx.h" /* from the private lib dir */
#include "getpart.h"
+#ifdef ENABLE_IPV6
+#define SWS_IPV6
+#endif
+
#ifndef FALSE
#define FALSE 0
#endif
@@ -709,19 +713,46 @@ static void win32_cleanup(void)
}
#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];
}
}
@@ -740,10 +771,18 @@ int main(int argc, char *argv[])
#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);
}
@@ -754,12 +793,26 @@ int main(int argc, char *argv[])
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);
}
@@ -771,6 +824,14 @@ int main(int argc, char *argv[])
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);