NetBSD Problem Report #60229

From www@netbsd.org  Mon May  4 20:48:06 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "R13" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id C50091A9239
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  4 May 2026 20:48:06 +0000 (UTC)
Message-Id: <20260504204805.C53291A923C@mollari.NetBSD.org>
Date: Mon,  4 May 2026 20:48:05 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: bozohttpd: fails to print actual port number with `-I 0'
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60229
>Category:       bin
>Synopsis:       bozohttpd: fails to print actual port number with `-I 0'
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 04 20:50:00 +0000 2026
>Last-Modified:  Tue May 05 10:40:01 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current, 11, 10, 9, ...
>Organization:
The NetBozod Localhost, Inc.
>Environment:
>Description:
$ /usr/libexec/httpd -b -f -s -i localhost -I 0 -X . localhost
started in daemon mode as `localhost' port `0' root `.'

This is not helpful: I want the port number the OS chose.

(Reliable machine-parseable output would be nice too.)
>How-To-Repeat:
as above
>Fix:
getsockname

>Audit-Trail:
From: Sunil Nimmagadda <sunil@nimmagadda.net>
To: gnats-bugs@netbsd.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: bin/60229: bozohttpd: fails to print actual port number with
 `-I 0'
Date: Tue, 05 May 2026 16:03:17 +0530

 --=-=-=
 Content-Type: text/plain

 "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org> writes:

 >>Number:         60229
 >>Category:       bin
 >>Synopsis:       bozohttpd: fails to print actual port number with `-I 0'
 >>Confidential:   no
 >>Severity:       serious
 >>Priority:       medium
 >>Responsible:    bin-bug-people
 >>State:          open
 >>Class:          sw-bug
 >>Submitter-Id:   net
 >>Arrival-Date:   Mon May 04 20:50:00 +0000 2026
 >>Originator:     Taylor R Campbell
 >>Release:        current, 11, 10, 9, ...
 >>Organization:
 > The NetBozod Localhost, Inc.
 >>Environment:
 >>Description:
 > $ /usr/libexec/httpd -b -f -s -i localhost -I 0 -X . localhost
 > started in daemon mode as `localhost' port `0' root `.'
 >
 > This is not helpful: I want the port number the OS chose.
 >
 > (Reliable machine-parseable output would be nice too.)
 >>How-To-Repeat:
 > as above
 >>Fix:
 > getsockname

 This patch prints the numerical host and port upon listen(2)...

 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: inline; filename=bozohttpd.diff
 Content-Description: bozohttpd: print ephemeral port chosen by OS

 diff --git a/libexec/httpd/daemon-bozo.c b/libexec/httpd/daemon-bozo.c
 index 64483d07c986..a1b741af84fa 100644
 --- a/libexec/httpd/daemon-bozo.c
 +++ b/libexec/httpd/daemon-bozo.c
 @@ -125,8 +125,11 @@ create_pidfile(bozohttpd_t *httpd)
  void
  bozo_daemon_init(bozohttpd_t *httpd)
  {
 +	struct sockaddr_storage ss;
  	struct addrinfo h, *r, *r0;
 +	char host[NI_MAXHOST], port[NI_MAXSERV];
  	const char	*portnum;
 +	socklen_t slen;
  	int e, i, on = 1;

  	if (!httpd->background && !httpd->foreground)
 @@ -137,6 +140,7 @@ bozo_daemon_init(bozohttpd_t *httpd)

  	portnum = httpd->bindport ? httpd->bindport : httpd->defbindport;

 +	slen = sizeof(ss);
  	memset(&h, 0, sizeof(h));
  	h.ai_family = PF_UNSPEC;
  	h.ai_socktype = SOCK_STREAM;
 @@ -162,6 +166,14 @@ bozo_daemon_init(bozohttpd_t *httpd)
  			continue;
  		if (listen(httpd->sock[i], SOMAXCONN) == -1)
  			continue;
 +		memset(&ss, 0, slen);
 +		if (getsockname(httpd->sock[i], (struct sockaddr *)(void *)&ss,
 +		    &slen) == 0 &&
 +		    getnameinfo((struct sockaddr *)&ss, slen,
 +		        host, sizeof(host), port, sizeof(port),
 +			NI_NUMERICHOST | NI_NUMERICSERV) == 0)
 +			bozowarn(httpd, "listening on host: %s port: %s",
 +			    host, port);
  		httpd->fds[i].events = POLLIN | POLLPRI | POLLRDNORM |
  				POLLRDBAND | POLLERR;
  		httpd->fds[i].fd = httpd->sock[i];

 --=-=-=--

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.