[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-net
Subject:    Re: bind() to ::1 fails with EADDRNOTAVAIL / clang vs gcc
From:       Jan Schaumann via freebsd-net <freebsd-net () freebsd ! org>
Date:       2021-11-24 3:36:58
Message-ID: 20211124033658.GC11277 () netmeister ! org
[Download RAW message or body]

Jan Schaumann via freebsd-net <freebsd-net@freebsd.org> wrote:
> Konstantin Belousov <kostikbel@gmail.com> 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%<value>", which is why this fails.

Fun.

-Jan

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic