[英]connect to IPv4 mapped IPv6 address fails
I am attempting to use an IPv6 socket to connect to an IPv4 address using an IPv4 mapped IPv6 address, on linux (debian-lenny-64 2.6.26-2-amd64) 我正在尝试在Linux(debian-lenny-64 2.6.26-2-amd64)上使用IPv6套接字使用IPv4映射的IPv6地址连接到IPv4地址。
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, void **argv)
{
struct addrinfo *sa;
struct addrinfo *ra;
int err = getaddrinfo("2001:DB8::2", 0, 0, &sa);
int fd = socket(sa->ai_family, SOCK_DGRAM, 0);
int v6only = 0;
err = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&v6only, sizeof(v6only));
err = bind(fd, sa->ai_addr, sa->ai_addrlen);
err = getaddrinfo("::ffff:192.168.0.1", "9", 0, &ra);
// err = getaddrinfo("2001:DB8::1", "9", 0, &ra);
// err = getaddrinfo("::ffff:127.0.0.1", "9", 0, &ra);
err = connect(fd, (struct sockaddr *)ra->ai_addr, sizeof(struct sockaddr_in6));
}
(I've removed error testing from the pasted code) (我已从粘贴的代码中删除了错误测试)
2001:DB8::2 and 192.168.0.2 are local addresses (both on the same interface). 2001:DB8 :: 2和192.168.0.2是本地地址(都在同一接口上)。
2001:DB8::1 and 192.168.0.1 are the remote addresses (both on the same interface). 2001:DB8 :: 1和192.168.0.1是远程地址(都在同一接口上)。
I change the remote address for the connect call and get the following: 我更改了connect呼叫的远程地址并获得以下信息:
If I change to doing IPv4 connects then the connects also work. 如果我更改为进行IPv4连接,则连接也可以使用。
I think there must be an issue with routing somewhere but I'm at a loss to work out what I need to change. 我认为在某处路由肯定存在问题,但是我很茫然,无法确定需要更改的内容。 Firstly should I in theory be able to do this?
首先,我理论上应该能够做到这一点吗?
Any ideas what is going wrong? 任何想法出了什么问题?
~$ man getaddrinfo
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.