diff options
| author | mrg <mrg@NetBSD.org> | 2011-11-17 22:09:12 +0000 |
|---|---|---|
| committer | mrg <mrg@NetBSD.org> | 2011-11-17 22:09:12 +0000 |
| commit | 4299c1c7f2bcb12bbf7d00fae613f54e19e6ae1e (patch) | |
| tree | 93527fdca094b90be318c8191ec91549bd1b6388 /libexec/httpd | |
| parent | 32cfb9c3a49ce98d091a0803957a9cf1665819cc (diff) | |
allow the -I option to be useful in non-daemon mode, by letting it force
the returned port number
Diffstat (limited to 'libexec/httpd')
| -rw-r--r-- | libexec/httpd/bozohttpd.8 | 14 | ||||
| -rw-r--r-- | libexec/httpd/bozohttpd.c | 26 | ||||
| -rw-r--r-- | libexec/httpd/main.c | 10 |
3 files changed, 33 insertions, 17 deletions
diff --git a/libexec/httpd/bozohttpd.8 b/libexec/httpd/bozohttpd.8 index 6b10f7585b3..4287983ec26 100644 --- a/libexec/httpd/bozohttpd.8 +++ b/libexec/httpd/bozohttpd.8 @@ -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 diff --git a/libexec/httpd/bozohttpd.c b/libexec/httpd/bozohttpd.c index 3fc803777da..abf8da7875b 100644 --- a/libexec/httpd/bozohttpd.c +++ b/libexec/httpd/bozohttpd.c @@ -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); diff --git a/libexec/httpd/main.c b/libexec/httpd/main.c index 0237727a510..0569c01a14a 100644 --- a/libexec/httpd/main.c +++ b/libexec/httpd/main.c @@ -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; |
