1
0
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:
Matias Fontanini
2018-03-18 12:56:12 -07:00
parent de4791f0c7
commit 544aa1b339
2 changed files with 7 additions and 3 deletions

View File

@@ -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

View File

@@ -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());
}