Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Jun 2022 19:21:12 +0200
From:      tuexen@freebsd.org
To:        Chris Ross <cross+freebsd@distal.com>
Cc:        freebsd-net <freebsd-net@freebsd.org>, freebsd-transport@freebsd.org
Subject:   Re: Troubles with adding IPv6 support to a program
Message-ID:  <91695911-4B92-4D3D-A532-9D51B8ACB22F@freebsd.org>
In-Reply-To: <AFA64D16-9FE9-42BF-AB5B-732F474037AB@distal.com>
References:  <AFA64D16-9FE9-42BF-AB5B-732F474037AB@distal.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> On 12. Jun 2022, at 18:40, Chris Ross <cross+freebsd@distal.com> =
wrote:
>=20
>=20
> Tl;dr;
> I don=E2=80=99t know why I=E2=80=99m getting an EINVAL from a call to =
bind for a second socket
>=20
>=20
>=20
>=20
> 20 years ago, I spent a lot of time adding IPv6 support to IPv4-only =
programs.
> So I thought this (adding IPv6 support to simpleproxy[1]) would be an =
easy
> project to pick up.  I=E2=80=99ve gotten most of the framework in, =
delayed only
> slightly when I learned that FreeBSD is =E2=80=9Cdifferent=E2=80=9D in =
not routing IPv4
> traffic to AF_INET6 sockets [2].
>=20
> However, I=E2=80=99m getting an issue from one of my bind(2) calls =
that I=E2=80=99m not able
> to figure out.  I was hoping someone else had a few minutes to take a =
quick
> look and help me find out what I=E2=80=99m doing wrong.
>=20
> A ~70 line relevant section of the source is at =
https://justpaste.it/6u3jd
>=20
> The tl;dr; of this is that I:
>=20
> * getaddrinfo(NULL, portIwant)
> * for each address returned:
> * create a socket
> * setsockopt(SO_REUSEADDR)
> * bind
> * listen
>=20
> The first address I get is IPv6 localhost, and that binds and listens, =
then
> continues to the next address.  A new socket is created, =
setsockopt=E2=80=99d, but
> bind for the second address (IPv4 localhost) fails with EINVAL.
>=20
> As you can see in the code shared, I have lots of debugging logs in =
the code,
> and it looks like everything is as it should be.  I=E2=80=99m probably =
just missing
> Something simple, and am looking for another set of eyes.
>=20
> Thanks all.  Contact me off list if you like, or on-list if it=E2=80=99s=
 obvious
> what I=E2=80=99ve done and it will help others.
Can you provide the output of

truss whatever_you_need_to_call_your_program

which shows the socket call and the failing bind call?

Best regards
Michael
>=20
>              - Chris
>=20
>=20
> [1] https://github.com/vzaliva/simpleproxy
> [2] inet6(4), "Interaction between IPv4/v6 sockets"
>=20




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?91695911-4B92-4D3D-A532-9D51B8ACB22F>