diff --git a/include/netutils/icmp_ping.h b/include/netutils/icmp_ping.h index 3f8d6c29d..d9164afc1 100644 --- a/include/netutils/icmp_ping.h +++ b/include/netutils/icmp_ping.h @@ -51,6 +51,7 @@ #define ICMP_E_RECVFROM -13 /* extra: error code */ #define ICMP_E_RECVSMALL -15 /* extra: recv bytes */ #define ICMP_E_BINDDEV -17 /* extra: error bind */ +#define ICMP_E_FILTER -19 /* extra: error filter */ /* Negative even number represent warning(recoverable) */ diff --git a/netutils/ping/icmp_ping.c b/netutils/ping/icmp_ping.c index aa88d0a18..88f006b8f 100644 --- a/netutils/ping/icmp_ping.c +++ b/netutils/ping/icmp_ping.c @@ -54,6 +54,7 @@ ****************************************************************************/ #define ICMP_IOBUFFER_SIZE(x) (sizeof(struct icmp_hdr_s) + (x)) +#define ICMP_SET_FILTER(t) (~(1U << (t))) /**************************************************************************** * Private Types @@ -226,6 +227,9 @@ void icmp_ping(FAR const struct ping_info_s *info) int ret; int ch; int i; +#ifdef CONFIG_NET_SOCKOPTS + int filter; +#endif g_exiting = false; #ifdef CONFIG_ENABLE_ALL_SIGNALS @@ -278,6 +282,19 @@ void icmp_ping(FAR const struct ping_info_s *info) } #endif +#ifdef CONFIG_NET_SOCKOPTS + filter = ICMP_SET_FILTER(ICMP_ECHO_REPLY); + ret = setsockopt(priv->sockfd, IPPROTO_ICMP, ICMP_FILTER, + &filter, sizeof(filter)); + if (ret < 0) + { + icmp_callback(&result, ICMP_E_FILTER, errno); + close(priv->sockfd); + free(priv); + return; + } +#endif + priv->kickoff = clock(); memset(&priv->destaddr, 0, sizeof(struct sockaddr_in));