From d9eadc5c0959c2cf8d8c59607041132f48e7f9cc Mon Sep 17 00:00:00 2001 From: Blaok Date: Mon, 27 Oct 2014 02:45:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96IPv6?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91=E6=BA=90=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 已经证实IPv6重定向是可以正确获取源地址的,原有问题出在用于显示地址格式函数上面,字节序什么的似乎不对,只是显示有问题,直接打印结构体显示IPv6地址完全正确。 偷懒特么坑爹啊,早点自己打印地址就好了…… --- src/redir.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/redir.c b/src/redir.c index 67ad39b2..a73da115 100644 --- a/src/redir.c +++ b/src/redir.c @@ -627,16 +627,14 @@ static void accept_cb (EV_P_ ev_io *w, int revents) //err = getdestaddr(listener, &destaddr); printf("Connet server %s, port %s.\n",listener->remote_addr->host,listener->remote_addr->port); - printf("%d %s\n",listener->sock.sa_family,listener->sock.sa_data); socklen_t socklen = sizeof(destaddr); //err = getsockopt(listener->fd, (listener->local.isIPv6()?SOL_IP6:SOL_IP), (listener->local.isIPv6()?IP6T_SO_ORIGINAL_DST:SO_ORIGINAL_DST), destaddr, &socklen); - err = getsockopt(clientfd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, &destaddr, &socklen); - // - char str[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET6, &destaddr, str, INET6_ADDRSTRLEN); - printf("%s\n", str); - - + err = getsockopt(clientfd, SOL_IPV6, IP6T_SO_ORIGINAL_DST, &destaddr, &socklen); + unsigned char * ipv6addrr=(unsigned char*)(&destaddr.sin6_addr); + printf("sizeofaddr=%d connecting:",(int)(sizeof(destaddr.sin6_addr))); + for(int iii=0;iii<16;++iii) + printf("%02x",ipv6addrr[iii]); + printf("\n"); if (err) { ERROR("getdestaddr");