Thanks itojun.
But in the code segment between the for .....
for (res = res0; res; res = res->ai_next) {
....
}
still opens an AF_INET socket.
It the socket is AF_INET6 ( as asked in the question )
then the app will need to convert the IPv4 address (in res) to IPv4
Mapped IPv6 adresses ( RFC 2553), if the getaddrinfo invocation is as
indicated in the given code.
Alternatively, one can use the option AI_V4MAPPED while calling
getaddrinfo(), so that the address you are returned itself is in
V4MAPPED format.
The only thing I want to impress is that you can still talk to IPv4
adresses ( hosts) using AF_INET6 sockets using Mapped addresses.
The choice between the 2 approaches can be left to the implementor
depending on his specific requirement.
regards,
Sukhdeep
>>> <[EMAIL PROTECTED]> 09/20/02 12:09AM >>>
> I am just thinking about this particular scenario: I have made an
IPv6
>compliant application (i.e. the socket is AF_INET6) that receives a
URL
>to connect to the other side. Upon resolution of the DNS it finds the
>address is IPv4. Can this address be correctly routed to the IPv4
host
>and back. What code precaautions will I have to take?
use getaddrinfo.
itojun
char *dst;
char *port;
int s;
struct addrinfo hints, *res, *res0;
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(dst, port, &hints, &res0);
if (error) {
fprintf(stderr, "%s\n", gai_strerror(error));
exit(1);
}
for (res = res0; res; res = res->ai_next) {
s = socket(res->ai_family, res->ai_socktype,
res->ai_protocol);
if (s < 0)
continue;
if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
close(s);
continue;
}
freeaddrinfo(res0);
/* do your stuff */
exit(0);
}
freeaddrinfo(res0);
fprintf(stderr, "connection failed\n");
exit(1);
---------------------------------------------------------------------
The IPv6 Users Mailing List
Unsubscribe by sending "unsubscribe users" to [EMAIL PROTECTED]
---------------------------------------------------------------------
The IPv6 Users Mailing List
Unsubscribe by sending "unsubscribe users" to [EMAIL PROTECTED]