diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-10-23 14:26:59 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-10-23 14:26:59 -0400 |
commit | 235602373c04aa38b7f8c93e6efbd9276ecc2266 (patch) | |
tree | 97c39e67902dd84d088ab930d8675e90760a674a /src/c | |
parent | c921d0df325c803fed8c7742eb088cb3d030d541 (diff) | |
parent | 20f3308b8c2a5a331239839e222bd21befde73eb (diff) |
Merge branch 'upstream' into dfsg_clean20161022+dfsg
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/Makefile.am | 7 | ||||
-rw-r--r-- | src/c/http.c | 41 |
2 files changed, 35 insertions, 13 deletions
diff --git a/src/c/Makefile.am b/src/c/Makefile.am index d117d018..f4d9bef8 100644 --- a/src/c/Makefile.am +++ b/src/c/Makefile.am @@ -8,9 +8,14 @@ liburweb_static_la_SOURCES = static.c AM_CPPFLAGS = -I$(srcdir)/../../include/urweb $(OPENSSL_INCLUDES) AM_CFLAGS = -Wimplicit -Wall -Werror -Wno-format-security -Wno-deprecated-declarations -U_FORTIFY_SOURCE $(PTHREAD_CFLAGS) -liburweb_la_LDFLAGS = $(AM_LDFLAGS) $(OPENSSL_LDFLAGS) +liburweb_la_LDFLAGS = $(AM_LDFLAGS) $(OPENSSL_LDFLAGS) \ + -export-symbols-regex '^(client_pruner|pthread_create_big|strcmp_nullsafe|uw_.*)' liburweb_la_LIBADD = $(PTHREAD_LIBS) -lm $(OPENSSL_LIBS) liburweb_http_la_LIBADD = liburweb.la +liburweb_http_la_LDFLAGS = -export-symbols-regex '^(main|uw_.*)' liburweb_cgi_la_LIBADD = liburweb.la +liburweb_cgi_la_LDFLAGS = -export-symbols-regex '^(main|uw_.*)' liburweb_fastcgi_la_LIBADD = liburweb.la +liburweb_fastcgi_la_LDFLAGS = -export-symbols-regex '^(main|uw_.*)' liburweb_static_la_LIBADD = liburweb.la +liburweb_static_la_LDFLAGS = -export-symbols-regex '^(main|uw_.*)' diff --git a/src/c/http.c b/src/c/http.c index 9059746f..d186e209 100644 --- a/src/c/http.c +++ b/src/c/http.c @@ -314,7 +314,7 @@ static void *worker(void *data) { } static void help(char *cmd) { - printf("Usage: %s [-p <port>] [-a <IP address>] [-t <thread count>] [-k] [-q] [-T SEC]\nThe '-k' option turns on HTTP keepalive.\nThe '-q' option turns off some chatter on stdout.\nThe '-T' option sets socket recv timeout (0 disables timeout, default is 5 sec).\n", cmd); + printf("Usage: %s [-p <port>] [-a <IPv4 address>] [-A <IPv6 address>] [-t <thread count>] [-k] [-q] [-T SEC]\nThe '-k' option turns on HTTP keepalive.\nThe '-q' option turns off some chatter on stdout.\nThe '-T' option sets socket recv timeout (0 disables timeout, default is 5 sec).\n", cmd); } static void sigint(int signum) { @@ -325,19 +325,18 @@ static void sigint(int signum) { int main(int argc, char *argv[]) { // The skeleton for this function comes from Beej's sockets tutorial. int sockfd; // listen on sock_fd - struct sockaddr_in my_addr; - struct sockaddr_in their_addr; // connector's address information + struct sockaddr_in6 my_addr; + struct sockaddr_in6 their_addr; // connector's address information socklen_t sin_size; - int yes = 1, uw_port = 8080, nthreads = 1, i, *names, opt; + int yes = 1, no = 0, uw_port = 8080, nthreads = 1, i, *names, opt; int recv_timeout_sec = 5; signal(SIGINT, sigint); signal(SIGPIPE, SIG_IGN); - my_addr.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP - memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); + my_addr.sin6_addr = in6addr_any; // auto-fill with my IP - while ((opt = getopt(argc, argv, "hp:a:t:kqT:")) != -1) { + while ((opt = getopt(argc, argv, "hp:a:A:t:kqT:")) != -1) { switch (opt) { case '?': fprintf(stderr, "Unknown command-line option\n"); @@ -358,8 +357,21 @@ int main(int argc, char *argv[]) { break; case 'a': - if (!inet_pton(AF_INET, optarg, &my_addr.sin_addr)) { - fprintf(stderr, "Invalid IP address\n"); + { + char *buf = alloca(strlen(optarg) + 8); + strcpy(buf, "::FFFF:"); + strcpy(buf + 7, optarg); + if (!inet_pton(AF_INET6, buf, &my_addr.sin6_addr)) { + fprintf(stderr, "Invalid IPv4 address\n"); + help(argv[0]); + return 1; + } + } + break; + + case 'A': + if (!inet_pton(AF_INET6, optarg, &my_addr.sin6_addr)) { + fprintf(stderr, "Invalid IPv6 address\n"); help(argv[0]); return 1; } @@ -401,7 +413,7 @@ int main(int argc, char *argv[]) { names = calloc(nthreads, sizeof(int)); - sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking! + sockfd = socket(AF_INET6, SOCK_STREAM, 0); // do some error checking! if (sockfd < 0) { fprintf(stderr, "Listener socket creation failed\n"); @@ -413,8 +425,13 @@ int main(int argc, char *argv[]) { return 1; } - my_addr.sin_family = AF_INET; // host byte order - my_addr.sin_port = htons(uw_port); // short, network byte order + if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(int)) < 0) { + fprintf(stderr, "Listener IPV6_V6ONLY option resetting failed\n"); + return 1; + } + + my_addr.sin6_family = AF_INET6; // host byte order + my_addr.sin6_port = htons(uw_port); // short, network byte order if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) < 0) { fprintf(stderr, "Listener socket bind failed\n"); |