Re: broken IPv6 code
>>>>> "yoshfuji" == yoshfuji <YOSHIFUJI> writes:
yoshfuji> No, it is not standard. In fact, there're NO standards.
yoshfuji> On RFC 2553 compliance systems, ipv4 communication
yoshfuji> should go to ipv6 socket in ipv4-mapped manner.
yoshfuji> However, bind(2) behavior is not specified, and is
yoshfuji> different between systems, such as NetBSD, FreeBSD,
yoshfuji> Linux and Solaris. Situation is very complicated and
yoshfuji> server application must be coded carefully.
This would seem to be a bad situation, and makes writing portable code
impossible.
Then again, what is the correct way of doing this on Linux?
<URL:http://people.debian.org/~csmall/ipv6/> has a link to
<URL:http://www.kame.net/newsletter/19980604/> which has a
very similar looking loop to Heimdal:
Heimdal code:
memset (&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo (NULL, portstr, &hints, &ai);
[...]
for (i = 0, a = ai; a != NULL; a = a->ai_next) {
fds[i] = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
[...]
socket_set_reuseaddr (fds[i], 1);
[...]
bind (fds[i], a->ai_addr, a->ai_addrlen);
[...]
listen (fds[i], SOMAXCONN);
[...]
}
webpage code:
struct addrinfo hints;
struct addrinfo *res;
char *myservice;
memset(&hints, 0, sizeof(hints));
/* set-up hints structure */
hints.ai_family = PF_UNSPEC;
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(NULL, myservice, &hints, &res);
if (error)
perror(gai_strerror(error));
else {
/*
* "res" has a chain of addrinfo structure filled with
* 0.0.0.0 (for IPv4), 0:0:0:0:0:0:0:0 (for IPv6) and alike,
* with port filled for "myservice".
*/
while (res) {
/* bind() and listen() to res->ai_addr */
}
}
Is this wrong? If it is, then perhaps the link to the bad web page
should be removed?
--
Brian May <bam@debian.org>
Reply to: