diff --git a/netutils/ping/icmpv6_ping.c b/netutils/ping/icmpv6_ping.c index e6a93fc986e..c62c329d6f2 100644 --- a/netutils/ping/icmpv6_ping.c +++ b/netutils/ping/icmpv6_ping.c @@ -42,6 +42,7 @@ #endif #include +#include #include #include @@ -169,6 +170,7 @@ void icmp6_ping(FAR const struct ping6_info_s *info) struct ping6_result_s result; struct sockaddr_in6 destaddr; struct sockaddr_in6 fromaddr; + struct icmp6_filter filter; struct icmpv6_echo_request_s outhdr; FAR struct icmpv6_echo_reply_s *inhdr; struct pollfd recvfd; @@ -210,7 +212,7 @@ void icmp6_ping(FAR const struct ping6_info_s *info) return; } - sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMP6); + sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); if (sockfd < 0) { icmp6_callback(&result, ICMPv6_E_SOCKET, errno); @@ -232,6 +234,20 @@ void icmp6_ping(FAR const struct ping6_info_s *info) } #endif + memset(&filter, 0xff, sizeof(filter)); + + /* ICMPv6_ECHO_REPLY >> 5 = 4 */ + + filter.icmp6_filt[4] &= ~(1 << (ICMPv6_ECHO_REPLY & 31)); + if (setsockopt(sockfd, SOL_ICMPV6, ICMP6_FILTER, &filter, + sizeof(filter)) < 0) + { + icmp6_callback(&result, ICMPv6_E_SOCKET, errno); + close(sockfd); + free(iobuffer); + return; + } + kickoff = clock(); memset(&destaddr, 0, sizeof(struct sockaddr_in6));