From cd6b0ee0c434d4b3b9392be0511463c5f8b3c3c8 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Sat, 4 Jun 2022 12:22:55 +0800 Subject: [PATCH] fix peer ip error --- srt/Packet.cpp | 12 +++++++++--- srt/SrtSession.cpp | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/srt/Packet.cpp b/srt/Packet.cpp index 085c56a0..38c5c147 100644 --- a/srt/Packet.cpp +++ b/srt/Packet.cpp @@ -419,9 +419,15 @@ void HandshakePacket::assignPeerIP(struct sockaddr_storage* addr){ struct sockaddr_in * ipv4 = (struct sockaddr_in *)addr; //抓包 奇怪好像是小头端??? storeUint32LE(peer_ip_addr,ipv4->sin_addr.s_addr); - }else{ - const sockaddr_in6* ipv6 = (struct sockaddr_in6 *)addr; - memcpy(peer_ip_addr,ipv6->sin6_addr.s6_addr,sizeof(peer_ip_addr)*sizeof(peer_ip_addr[0])); + }else if(addr->ss_family == AF_INET6){ + if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) { + struct in_addr addr4; + memcpy(&addr4, 12 + (char *)&(((struct sockaddr_in6 *)addr)->sin6_addr), 4); + storeUint32LE(peer_ip_addr,addr4.s_addr); + }else{ + const sockaddr_in6* ipv6 = (struct sockaddr_in6 *)addr; + memcpy(peer_ip_addr,ipv6->sin6_addr.s6_addr,sizeof(peer_ip_addr)*sizeof(peer_ip_addr[0])); + } } } uint32_t HandshakePacket::generateSynCookie(struct sockaddr_storage* addr,TimePoint ts,uint32_t current_cookie, int correction ){ diff --git a/srt/SrtSession.cpp b/srt/SrtSession.cpp index 17a2eff0..978e28da 100644 --- a/srt/SrtSession.cpp +++ b/srt/SrtSession.cpp @@ -11,9 +11,9 @@ SrtSession::SrtSession(const Socket::Ptr &sock) : UdpSession(sock) { socklen_t addr_len = sizeof(_peer_addr); memset(&_peer_addr,0,addr_len); - TraceL<<"before addr len "<rawFD(), (struct sockaddr *)&_peer_addr, &addr_len); - TraceL<<"after addr len "<