1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 20:24:26 +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

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