diff --git a/include/netutils/icmp_ping.h b/include/netutils/icmp_ping.h index 3f8d6c29d86..d9164afc104 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 7aa1d397390..ee53f4d8f16 100644 --- a/netutils/ping/icmp_ping.c +++ b/netutils/ping/icmp_ping.c @@ -53,6 +53,7 @@ ****************************************************************************/ #define ICMP_IOBUFFER_SIZE(x) (sizeof(struct icmp_hdr_s) + (x)) +#define ICMP_SET_FILTER(t) (~(1U << (t))) /**************************************************************************** * Private Types @@ -197,6 +198,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; signal(SIGINT, sigexit); @@ -246,6 +250,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));