Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/netutils/icmp_ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */

Expand Down
17 changes: 17 additions & 0 deletions netutils/ping/icmp_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
****************************************************************************/

#define ICMP_IOBUFFER_SIZE(x) (sizeof(struct icmp_hdr_s) + (x))
#define ICMP_SET_FILTER(t) (~(1U << (t)))

/****************************************************************************
* Private Types
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Loading