diff --git a/src/ipv6.cpp b/src/ipv6.cpp index fcb7c87..49f6622 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -305,7 +305,10 @@ void IPv6::send(PacketSender& sender, const NetworkInterface &) { } PDU* IPv6::recv_response(PacketSender& sender, const NetworkInterface &) { - const PacketSender::SocketType type = PacketSender::ICMPV6_SOCKET; + PacketSender::SocketType type = PacketSender::IPV6_SOCKET; + if (inner_pdu() && inner_pdu()->pdu_type() == PDU::ICMPv6) { + type = PacketSender::ICMPV6_SOCKET; + } return sender.recv_l3(*this, 0, sizeof(sockaddr_in6), type); } #endif diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index eb7a6db..c7a91e2 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -252,8 +252,9 @@ void PacketSender::open_l3_socket(SocketType type) { throw invalid_socket_type(); } if (sockets_[type] == INVALID_RAW_SOCKET) { + const bool is_v6 = (type == IPV6_SOCKET || type == ICMPV6_SOCKET); socket_type sockfd; - sockfd = socket((type == IPV6_SOCKET) ? AF_INET6 : AF_INET, SOCK_RAW, socktype); + sockfd = socket(is_v6 ? AF_INET6 : AF_INET, SOCK_RAW, socktype); if (sockfd < 0) { throw socket_open_error(make_error_string()); } @@ -264,7 +265,7 @@ void PacketSender::open_l3_socket(SocketType type) { #else typedef const char* option_ptr; #endif - const int level = (type == IPV6_SOCKET) ? IPPROTO_IPV6 : IPPROTO_IP; + const int level = (is_v6) ? IPPROTO_IPV6 : IPPROTO_IP; if (setsockopt(sockfd, level, IP_HDRINCL, (option_ptr)&on, sizeof(on)) != 0) { throw socket_open_error(make_error_string()); }