Re: defaulting to net.ipv6.bindv6only=1 for squeeze
Am Mittwoch 23 Dezember 2009 14:07:54 schrieb Jarek Kamiński:
> Na grupie linux.debian.devel napisałe(a)ś:
> > I have failures now with a client that cannot connect() to the IPv4
> > address but get an ENETUNREACH instead.
> > The application DOES set this socket option:
> > socket(PF_INET6, SOCK_STREAM, IPPROTO_IP) = 3
>
> ^-- You meant IPPROTO_TCP?
>
> > setsockopt(3, SOL_IPV6, IPV6_V6ONLY, [0], 4) = 0
> > bind(3, {sa_family=AF_INET6,....) = 0
> > listen(3, ....) = 0
> >
> > Did you ever test that "setting this option back to 0 by a program before
> > bind() and listen()" actually works?
>
> Yes. Following code actually works (runs with bindv6only enabled,
> listens on [::]:1234 and accepts connection made to localhost:1234):
> #v+
> #include <sys/socket.h>
> #include <netinet/in.h>
>
> int main ()
> {
> int no = 0;
> int listenfd = socket (AF_INET6, SOCK_STREAM, IPPROTO_TCP);
> int clientfd;
> char buf[1024];
> ssize_t rv;
> struct sockaddr_in6 addr = { AF_INET6, htons(1234), 0, IN6ADDR_ANY_INIT };
> setsockopt (listenfd, SOL_IPV6, IPV6_V6ONLY, &no, sizeof(no));
> bind (listenfd, (void*)&addr, sizeof(addr));
> listen (listenfd, 1);
> clientfd = accept (listenfd, 0, 0);
> while ((rv = read (clientfd, buf, sizeof(buf))) > 0)
> write (1, buf, rv);
> return 0;
> }
I do:
int v6only = 0;
int fd = socket(AF_INET6, SOCK_STREAM, 0);
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&v6only, sizeof(v6only));
bind(fd, (struct sockaddr *) &my_sock, sizeof(struct sockaddr_in6));
listen(fd, 2);
...
And the client cannot connect! The value of IPPROTO_IPV6 and SOL_IPV6 are both 41, thus this cannot be the cause.
Maybe the difference is the "0" vs. "IPPROTO_TCP"? "0" is supposed to work, though.
Additionally: what happens when I want to open an ::FFFF:127.0.0.1 as an IPv6 socket?
But even when using IN6ADDR_ANY, the client cannot connect to 127.0.0.1.
Thanks
HS
Reply to: