# HG changeset patch # User Adam Chlipala # Date 1340459200 14400 # Node ID 7095e1b7240b88e241afa9123bee2e104db6b93b # Parent 818d4097e2ed5ef255ded1a2c122ff3811a30608 HTTP daemons now take '-a' option to set IP address to listen on diff -r 818d4097e2ed -r 7095e1b7240b src/c/http.c --- a/src/c/http.c Sun Jun 03 11:29:31 2012 -0400 +++ b/src/c/http.c Sat Jun 23 09:46:40 2012 -0400 @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -217,7 +218,7 @@ } static void help(char *cmd) { - printf("Usage: %s [-p ] [-t ]\n", cmd); + printf("Usage: %s [-p ] [-a ] [-t ]\n", cmd); } static void sigint(int signum) { @@ -238,7 +239,10 @@ signal(SIGINT, sigint); signal(SIGPIPE, SIG_IGN); - while ((opt = getopt(argc, argv, "hp:t:")) != -1) { + my_addr.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP + memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); + + while ((opt = getopt(argc, argv, "hp:a:t:")) != -1) { switch (opt) { case '?': fprintf(stderr, "Unknown command-line option"); @@ -258,6 +262,14 @@ } break; + case 'a': + if (!inet_pton(AF_INET, optarg, &my_addr.sin_addr)) { + fprintf(stderr, "Invalid IP address\n"); + help(argv[0]); + return 1; + } + break; + case 't': nthreads = atoi(optarg); if (nthreads <= 0) { @@ -291,8 +303,6 @@ my_addr.sin_family = AF_INET; // host byte order my_addr.sin_port = htons(uw_port); // short, network byte order - my_addr.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP - memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof my_addr) < 0) { fprintf(stderr, "Listener socket bind failed\n");