add ipv6 support

This commit is contained in:
Thomas Porzelt 2009-09-13 16:36:27 +02:00
parent 993ed0a6b0
commit 4a454553a6
2 changed files with 16 additions and 9 deletions

1
TODO
View File

@ -3,5 +3,4 @@
- chunked encoding support - chunked encoding support
- ssl support - ssl support
- better error reporting - better error reporting
- ipv6 support
- pipelining - pipelining

View File

@ -15,14 +15,15 @@ extern int optind, optopt; /* getopt */
static void show_help(void) { static void show_help(void) {
printf("weighttp <options> <url>\n"); printf("weighttp <options> <url>\n");
printf(" -n num number of requests (mandatory)\n"); printf(" -n num number of requests (mandatory)\n");
printf(" -k keep alive (default: no)\n");
printf(" -t num threadcount (default: 1)\n"); printf(" -t num threadcount (default: 1)\n");
printf(" -c num concurrent clients (default: 1)\n"); printf(" -c num concurrent clients (default: 1)\n");
printf(" -k keep alive (default: no)\n");
printf(" -6 use ipv6 (default: no)\n");
printf(" -h show help and exit\n"); printf(" -h show help and exit\n");
printf(" -v show version and exit\n\n"); printf(" -v show version and exit\n\n");
} }
static struct addrinfo *resolve_host(char *hostname, uint16_t port) { static struct addrinfo *resolve_host(char *hostname, uint16_t port, uint8_t use_ipv6) {
int err; int err;
char port_str[6]; char port_str[6];
struct addrinfo hints, *res, *res_first, *res_last; struct addrinfo hints, *res, *res_first, *res_last;
@ -43,7 +44,9 @@ static struct addrinfo *resolve_host(char *hostname, uint16_t port) {
/* search for an ipv4 address, no ipv6 yet */ /* search for an ipv4 address, no ipv6 yet */
res_last = NULL; res_last = NULL;
for (res = res_first; res != NULL; res = res->ai_next) { for (res = res_first; res != NULL; res = res->ai_next) {
if (res->ai_family == AF_INET) if (res->ai_family == AF_INET && !use_ipv6)
break;
else if (res->ai_family == AF_INET6 && use_ipv6)
break; break;
res_last = res; res_last = res;
@ -165,6 +168,7 @@ int main(int argc, char *argv[]) {
Worker *worker; Worker *worker;
char *host; char *host;
uint16_t port; uint16_t port;
uint8_t use_ipv6;
uint16_t rest_concur, rest_req; uint16_t rest_concur, rest_req;
Stats stats; Stats stats;
ev_tstamp duration; ev_tstamp duration;
@ -176,12 +180,13 @@ int main(int argc, char *argv[]) {
printf("weighttp - a lightweight and simple webserver benchmarking tool\n\n"); printf("weighttp - a lightweight and simple webserver benchmarking tool\n\n");
/* default settings */ /* default settings */
use_ipv6 = 0;
config.thread_count = 1; config.thread_count = 1;
config.concur_count = 1; config.concur_count = 1;
config.req_count = 0; config.req_count = 0;
config.keep_alive = 0; config.keep_alive = 0;
while ((c = getopt(argc, argv, ":hvkn:t:c:")) != -1) { while ((c = getopt(argc, argv, ":hv6kn:t:c:")) != -1) {
switch (c) { switch (c) {
case 'h': case 'h':
show_help(); show_help();
@ -190,6 +195,9 @@ int main(int argc, char *argv[]) {
printf("version: " VERSION "\n"); printf("version: " VERSION "\n");
printf("build-date: " __DATE__ " " __TIME__ "\n\n"); printf("build-date: " __DATE__ " " __TIME__ "\n\n");
return 0; return 0;
case '6':
use_ipv6 = 1;
break;
case 'k': case 'k':
config.keep_alive = 1; config.keep_alive = 1;
break; break;
@ -257,7 +265,7 @@ int main(int argc, char *argv[]) {
//printf("host: '%s', port: %d\n", host, port); //printf("host: '%s', port: %d\n", host, port);
/* resolve hostname */ /* resolve hostname */
if(!(config.saddr = resolve_host(host, port))) { if(!(config.saddr = resolve_host(host, port, use_ipv6))) {
return 1; return 1;
} }