mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Don't assume IPv6 uses ICMPv6 underneath
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user