From nobody Wed Nov 24 03:36:58 2021 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E86D5189AAC1 for ; Wed, 24 Nov 2021 03:36:59 +0000 (UTC) (envelope-from jschauma@netmeister.org) Received: from panix.netmeister.org (panix.netmeister.org [IPv6:2001:470:30:84:e276:63ff:fe72:3900]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzRWt6d9Hz53Qd for ; Wed, 24 Nov 2021 03:36:58 +0000 (UTC) (envelope-from jschauma@netmeister.org) Received: by panix.netmeister.org (Postfix, from userid 1000) id 78FD28586F; Tue, 23 Nov 2021 22:36:58 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=netmeister.org; s=2021; t=1637725018; bh=hwiZSsLxZ4Owy9szFnLzLCeO95zwFe4EOUnPhSIyhck=; h=Date:From:To:Subject:References:In-Reply-To; b=Cz+64bmJaoS3IWDpY6uk4v4ZAzSB0daRKkW729pe9JGi3umYKRBCFIpt4EKR2isSB lzmIHrd2uO+ZXwhrjgCFTd7HnMLu3jTi6Jm0TpWjupWJ8WgMOzp9GnjY9zriwS9hkj AyNfo3bCDDSqNk7sUwyiUPr0HUwbV06L7EGf9060= Date: Tue, 23 Nov 2021 22:36:58 -0500 To: freebsd-net@freebsd.org Subject: Re: bind() to ::1 fails with EADDRNOTAVAIL / clang vs gcc Message-ID: <20211124033658.GC11277@netmeister.org> References: <20211124020839.GZ11277@netmeister.org> <20211124031010.GB11277@netmeister.org> List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211124031010.GB11277@netmeister.org> User-Agent: Mutt/1.11.1 (2018-12-01) X-Rspamd-Queue-Id: 4HzRWt6d9Hz53Qd X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=netmeister.org header.s=2021 header.b=Cz+64bmJ; dmarc=pass (policy=quarantine) header.from=netmeister.org; spf=pass (mx1.freebsd.org: domain of jschauma@netmeister.org designates 2001:470:30:84:e276:63ff:fe72:3900 as permitted sender) smtp.mailfrom=jschauma@netmeister.org X-Spamd-Result: default: False [-4.00 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[netmeister.org:s=2021]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+a]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCPT_COUNT_ONE(0.00)[1]; DKIM_TRACE(0.00)[netmeister.org:+]; DMARC_POLICY_ALLOW(-0.50)[netmeister.org,quarantine]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:2033, ipnet:2001:470:30::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[] Reply-To: jschauma@netmeister.org From: Jan Schaumann via freebsd-net X-Original-From: Jan Schaumann X-ThisMailContainsUnwantedMimeParts: N Jan Schaumann via freebsd-net wrote: > Konstantin Belousov wrote: > > On Tue, Nov 23, 2021 at 09:08:39PM -0500, Jan Schaumann via freebsd-net wrote: > > > > - Why does _any_ of those fail? > > > - Why does a.c succeed when compiled with clang, but > > > b.c does not? > > Most likely because you did not fully initialized *sin. > > > Really it is UB, try to memset(sin, 0, sizeof(*sin)). > > Nice, that works. Specifically, it looks like it's the sin6_scope_id that matters here: In the case where we have additional stack variables, 'sin->sin6_scope_id' ends up being set to '0', while in the other case it retains a random value. The random value then means that we're trying to bind not "::1", but "::1%", which is why this fails. Fun. -Jan