mailing list of musl libc
 help / color / Atom feed
* [musl] getaddrinfo(3) with AI_V4MAPPED and AI_ALL flags
@ 2020-02-27 10:17 Alexander Scherbatiy
  2020-02-27 14:45 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Scherbatiy @ 2020-02-27 10:17 UTC (permalink / raw)
  To: musl

Hello,

When I call getaddrinfo() with different families, SOCK_STREAM socktype, 
IPPROTO_TCP protocol, and AI_PASSIVE flag the result is the same on the 
Alpine Linux 3.11.3 and Ubuntu 19.10 (the code sample is below):

----------------

family: AF_UNSPEC, flags: AI_PASSIVE
AF_INET  IPv4 addr '0.0.0.0'
AF_INET6 IPv6 addr '::'

family: AF_INET,   flags: AI_PASSIVE
AF_INET  IPv4 addr '0.0.0.0'

family: AF_INET6,  flags: AI_PASSIVE
AF_INET6 IPv6 addr '::'

----------------

When I use getaddrinfo() with AF_INET6 family and additional AI_V4MAPPED 
| AI_ALL (return both IPv6 and IPv4-mapped IPv6 addresses) flags the 
result on Ubuntu contains only IPv6 '::' address:

----------------

family: AF_INET6,  flags: AI_PASSIVE | AI_V4MAPPED | AI_ALL
AF_INET6 IPv6 addr '::'

----------------

whereas the result on Alpine Linux contains both IPv4-mapped IPv6 
addresses '::ffff:0.0.0.0' and  IPv6 '::'

----------------

family: AF_INET6,  flags: AI_PASSIVE | AI_V4MAPPED | AI_ALL
AF_INET6 IPv6 addr '::ffff:0.0.0.0'
AF_INET6 IPv6 addr '::'

----------------

Is it expected behavior?

I use Alpine Linux 3.11.3 from docker with musl libc (x86_64).

Thanks,

Alexander.


Code sample:

-------------  addr_info.c -----------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <netdb.h>
#include <arpa/inet.h>


void sockaddr_show(struct sockaddr *sa) {

     int family = sa->sa_family;

     if (family == AF_INET) {
         char buff[INET_ADDRSTRLEN];
         struct sockaddr_in server_addr = *((struct sockaddr_in*) sa);
         inet_ntop(AF_INET, &server_addr.sin_addr, buff, INET_ADDRSTRLEN);
         printf("AF_INET  IPv4 addr '%s'\n", buff);
     } else if (family == AF_INET6) {
         char buff[INET_ADDRSTRLEN];
         struct sockaddr_in6 server_addr = *((struct sockaddr_in6*) sa);
         inet_ntop(AF_INET6, &server_addr.sin6_addr, buff, 
INET6_ADDRSTRLEN);
         printf("AF_INET6 IPv6 addr '%s'\n", buff);
     } else {
         printf("family: %d\n", family);
     }
}

void show_addr_info(int family, int flags) {

     char* hostname = NULL;
     char* service = "33833";

     struct addrinfo hints;
     struct addrinfo *result, *rp;

     memset (&hints, 0, sizeof(hints));

     hints.ai_family = family;
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_protocol = IPPROTO_TCP;
     hints.ai_flags = flags;

     int res = getaddrinfo(hostname, service, &hints, &result);
     for (rp = result; rp != NULL; rp = rp->ai_next) {
         sockaddr_show(rp->ai_addr);
     }
     printf("\n");
}

int main(void) {

     printf("family: AF_UNSPEC, flags: AI_PASSIVE\n");
     show_addr_info(AF_UNSPEC, AI_PASSIVE);

     printf("family: AF_INET,   flags: AI_PASSIVE\n");
     show_addr_info(AF_INET,   AI_PASSIVE);

     printf("family: AF_INET6,  flags: AI_PASSIVE\n");
     show_addr_info(AF_INET6,  AI_PASSIVE);

     printf("family: AF_INET6,  flags: AI_PASSIVE | AI_V4MAPPED | 
AI_ALL\n");
     show_addr_info(AF_INET6,  AI_PASSIVE | AI_V4MAPPED | AI_ALL);

     return EXIT_SUCCESS;
}

--------------------------------






^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [musl] getaddrinfo(3) with AI_V4MAPPED and AI_ALL flags
  2020-02-27 10:17 [musl] getaddrinfo(3) with AI_V4MAPPED and AI_ALL flags Alexander Scherbatiy
@ 2020-02-27 14:45 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2020-02-27 14:45 UTC (permalink / raw)
  To: musl

On Thu, Feb 27, 2020 at 01:17:20PM +0300, Alexander Scherbatiy wrote:
> Hello,
> 
> When I call getaddrinfo() with different families, SOCK_STREAM
> socktype, IPPROTO_TCP protocol, and AI_PASSIVE flag the result is
> the same on the Alpine Linux 3.11.3 and Ubuntu 19.10 (the code
> sample is below):
> 
> ----------------
> 
> family: AF_UNSPEC, flags: AI_PASSIVE
> AF_INET  IPv4 addr '0.0.0.0'
> AF_INET6 IPv6 addr '::'
> 
> family: AF_INET,   flags: AI_PASSIVE
> AF_INET  IPv4 addr '0.0.0.0'
> 
> family: AF_INET6,  flags: AI_PASSIVE
> AF_INET6 IPv6 addr '::'
> 
> ----------------
> 
> When I use getaddrinfo() with AF_INET6 family and additional
> AI_V4MAPPED | AI_ALL (return both IPv6 and IPv4-mapped IPv6
> addresses) flags the result on Ubuntu contains only IPv6 '::'
> address:
> 
> ----------------
> 
> family: AF_INET6,  flags: AI_PASSIVE | AI_V4MAPPED | AI_ALL
> AF_INET6 IPv6 addr '::'
> 
> ----------------
> 
> whereas the result on Alpine Linux contains both IPv4-mapped IPv6
> addresses '::ffff:0.0.0.0' and  IPv6 '::'
> 
> ----------------
> 
> family: AF_INET6,  flags: AI_PASSIVE | AI_V4MAPPED | AI_ALL
> AF_INET6 IPv6 addr '::ffff:0.0.0.0'
> AF_INET6 IPv6 addr '::'
> 
> ----------------
> 
> Is it expected behavior?
> 
> I use Alpine Linux 3.11.3 from docker with musl libc (x86_64).

The musl behavior is as intended and I think it's more correct. If
net.ipv6.bindv6only sysctl is enabled, binding using the glibc results
would fail to accept ipv4 connections.

Rich

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 10:17 [musl] getaddrinfo(3) with AI_V4MAPPED and AI_ALL flags Alexander Scherbatiy
2020-02-27 14:45 ` Rich Felker

mailing list of musl libc

Archives are clonable: git clone --mirror http://inbox.vuxu.org/musl

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git