Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Feb 2019 02:50:04 +0000
From:      Rick Macklem <rmacklem@uoguelph.ca>
To:        "Bjoern A. Zeeb" <bz@FreeBSD.org>
Cc:        "freebsd-current@FreeBSD.org" <freebsd-current@FreeBSD.org>
Subject:   Re: what do jails map 127.0.0.1 to?
Message-ID:  <QB1PR01MB353764CC569FA17BC08B5A2FDD660@QB1PR01MB3537.CANPRD01.PROD.OUTLOOK.COM>
In-Reply-To: <2F884512-F6A4-4E37-8566-46985A9FC5E3@FreeBSD.org>
References:  <QB1PR01MB3537028815A3502AA6BC4B9BDD640@QB1PR01MB3537.CANPRD01.PROD.OUTLOOK.COM>, <2F884512-F6A4-4E37-8566-46985A9FC5E3@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Bjoern A. Zeeb wrote:
[good stuff snipped]
>Yes, could do easily but wouldn=92t work for my above case, would it?  I
>can help you with the code for v4 and jails if you help me with the code
>for IPv6?
Well, not quite what you volunteered to do, but can you fill in the INET6 c=
ode
for this code snippet? (It does what Alan suggested for INET.)


	/*
	 * Find out what IP# localhost maps to and whether or not use of
	 * INET6 is required.  Jails will map 127.0.0.1 to another INET
	 * address.
	 */
	use_inet6 =3D 0;
	s =3D socket(PF_INET, SOCK_DGRAM, 0);
	if (s < 0) {
		use_inet6 =3D 1;
		s =3D socket(PF_INET6, SOCK_DGRAM, 0);
	}
	if (s < 0)
		err(1, "Can't create a inet/inet6 socket");
	if (use_inet6 !=3D 0) {
		;	/* Needs code... */
	} else {
		memset(&sad, 0, sizeof(sad));
		sad.sin_len =3D sizeof(sad);
		sad.sin_family =3D AF_INET;
		sad.sin_addr.s_addr =3D inet_addr("127.0.0.1");
		sad.sin_port =3D 0;
		ret =3D bind(s, (struct sockaddr *)&sad, sizeof(sad));
		if (ret > 0)
			err(1, "Can't bind 127.0.0.1");
		memset(&sad, 0, sizeof(sad));
		slen =3D sizeof(sad);
		ret =3D getsockname(s, (struct sockaddr *)&sad, &slen);
		if (ret < 0)
			err(1, "Can't get bound sockaddr");
		printf("locaddr: %s\n", inet_ntoa(sad.sin_addr));
	}

If the IPv4 code isn't sufficient, please let me know. (I think I know how =
to make
the RPC code use IPv6, but I need to know what IPv6 address to use. I get c=
onfused
by link local/site local/=85 It needs to be an address that is "this machin=
e".

Thanks for your help with this, rick



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?QB1PR01MB353764CC569FA17BC08B5A2FDD660>