Module Name: src Committed By: mrg Date: Thu Nov 17 22:09:12 UTC 2011
Modified Files: src/libexec/httpd: bozohttpd.8 bozohttpd.c main.c Log Message: allow the -I option to be useful in non-daemon mode, by letting it force the returned port number To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/libexec/httpd/bozohttpd.8 cvs rdiff -u -r1.28 -r1.29 src/libexec/httpd/bozohttpd.c cvs rdiff -u -r1.3 -r1.4 src/libexec/httpd/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/libexec/httpd/bozohttpd.8 diff -u src/libexec/httpd/bozohttpd.8:1.29 src/libexec/httpd/bozohttpd.8:1.30 --- src/libexec/httpd/bozohttpd.8:1.29 Sun Apr 24 07:18:59 2011 +++ src/libexec/httpd/bozohttpd.8 Thu Nov 17 22:09:12 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: bozohttpd.8,v 1.29 2011/04/24 07:18:59 jmmv Exp $ +.\" $NetBSD: bozohttpd.8,v 1.30 2011/11/17 22:09:12 mrg Exp $ .\" .\" $eterna: bozohttpd.8,v 1.99 2010/09/20 22:26:28 mrg Exp $ .\" @@ -135,14 +135,18 @@ Also see .Fl X . .It Fl I Ar port Causes +.Nm +to use .Ar port -to use used as the port to bind daemon mode. -The default is the +instead of the default .Dq http port. -This option is only valid with the +When used with the .Fl b -option. +option, it changes the bound port. +Otherwise it forces redirections to use this port instead of the +value obtained via +.Xr getsockname 2 . .It Fl i Ar address Causes .Ar address Index: src/libexec/httpd/bozohttpd.c diff -u src/libexec/httpd/bozohttpd.c:1.28 src/libexec/httpd/bozohttpd.c:1.29 --- src/libexec/httpd/bozohttpd.c:1.28 Sat Aug 27 15:33:59 2011 +++ src/libexec/httpd/bozohttpd.c Thu Nov 17 22:09:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.c,v 1.28 2011/08/27 15:33:59 joerg Exp $ */ +/* $NetBSD: bozohttpd.c,v 1.29 2011/11/17 22:09:12 mrg Exp $ */ /* $eterna: bozohttpd.c,v 1.176 2010/09/20 22:26:28 mrg Exp $ */ @@ -563,14 +563,26 @@ bozo_read_request(bozohttpd_t *httpd) if (addr != NULL) request->hr_remoteaddr = bozostrdup(request->hr_httpd, addr); slen = sizeof(ss); - if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0) - port = NULL; - else { - if (getnameinfo((struct sockaddr *)(void *)&ss, slen, NULL, 0, - bufport, sizeof bufport, NI_NUMERICSERV) == 0) - port = bufport; + + /* + * Override the bound port from the request value, so it works even + * if passed through a proxy that doesn't rewrite the port. + */ + if (httpd->bindport) { + if (strcmp(httpd->bindport, "80") != 0) + port = httpd->bindport; else port = NULL; + } else { + if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0) + port = NULL; + else { + if (getnameinfo((struct sockaddr *)(void *)&ss, slen, NULL, 0, + bufport, sizeof bufport, NI_NUMERICSERV) == 0) + port = bufport; + else + port = NULL; + } } if (port != NULL) request->hr_serverport = bozostrdup(request->hr_httpd, port); Index: src/libexec/httpd/main.c diff -u src/libexec/httpd/main.c:1.3 src/libexec/httpd/main.c:1.4 --- src/libexec/httpd/main.c:1.3 Sat Aug 27 15:33:59 2011 +++ src/libexec/httpd/main.c Thu Nov 17 22:09:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.3 2011/08/27 15:33:59 joerg Exp $ */ +/* $NetBSD: main.c,v 1.4 2011/11/17 22:09:12 mrg Exp $ */ /* $eterna: main.c,v 1.4 2010/07/11 00:34:28 mrg Exp $ */ /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ @@ -198,12 +198,15 @@ main(int argc, char **argv) bozo_set_pref(&prefs, "index.html", optarg); break; + case 'I': + bozo_set_pref(&prefs, "port number", optarg); + break; + #ifdef NO_DAEMON_MODE case 'b': case 'e': case 'f': case 'i': - case 'I': case 'P': bozo_err(&httpd, 1, "Daemon mode is not enabled"); /* NOTREACHED */ @@ -233,9 +236,6 @@ main(int argc, char **argv) bozo_set_pref(&prefs, "bind address", optarg); break; - case 'I': - bozo_set_pref(&prefs, "port number", optarg); - break; case 'P': bozo_set_pref(&prefs, "pid file", optarg); break;