Re: what do jails map 127.0.0.1 to?

From: Rodney W. Grimes <freebsd-rwg_at_pdx.rh.CN85.dnsmgr.net>
Date: Tue, 12 Feb 2019 19:04:52 -0800 (PST)
[ Charset windows-1252 unsupported, converting... ]
> 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".

ipv4 127.0.0.1 == ipv6 ::1, see /etc/hosts

> 
> Thanks for your help with this, rick
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
> 
> 

-- 
Rod Grimes                                                 rgrimes_at_freebsd.org
Received on Wed Feb 13 2019 - 02:04:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:20 UTC