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
_______________________________________________
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to