Browse Source

正确获取IPv6重定向源地址

已经证实IPv6重定向是可以正确获取源地址的,原有问题出在用于显示地址格式函数上面,字节序什么的似乎不对,只是显示有问题,直接打印结构体显示IPv6地址完全正确。
偷懒特么坑爹啊,早点自己打印地址就好了……
pull/131/head
Blaok 10 years ago
parent
commit
d9eadc5c09
1 changed files with 6 additions and 8 deletions
  1. 14
      src/redir.c

14
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");

Loading…
Cancel
Save