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’t 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 code
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 = 0;
s = socket(PF_INET, SOCK_DGRAM, 0);
if (s < 0) {
use_inet6 = 1;
s = socket(PF_INET6, SOCK_DGRAM, 0);
}
if (s < 0)
err(1, "Can't create a inet/inet6 socket");
if (use_inet6 != 0) {
; /* Needs code... */
} else {
memset(&sad, 0, sizeof(sad));
sad.sin_len = sizeof(sad);
sad.sin_family = AF_INET;
sad.sin_addr.s_addr = inet_addr("127.0.0.1");
sad.sin_port = 0;
ret = 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 = sizeof(sad);
ret = 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 confused
by link local/site local/… It needs to be an address that is "this machine".
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>
