File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 5151#define ICMP_E_RECVFROM -13 /* extra: error code */
5252#define ICMP_E_RECVSMALL -15 /* extra: recv bytes */
5353#define ICMP_E_BINDDEV -17 /* extra: error bind */
54+ #define ICMP_E_FILTER -19 /* extra: error filter */
5455
5556/* Negative even number represent warning(recoverable) */
5657
Original file line number Diff line number Diff line change 5353 ****************************************************************************/
5454
5555#define ICMP_IOBUFFER_SIZE (x ) (sizeof(struct icmp_hdr_s) + (x))
56+ #define ICMP_SET_FILTER (t ) (UINT32_MAX - (1U << (t)))
5657
5758/****************************************************************************
5859 * Private Types
@@ -197,6 +198,7 @@ void icmp_ping(FAR const struct ping_info_s *info)
197198 int ret ;
198199 int ch ;
199200 int i ;
201+ int filter ;
200202
201203 g_exiting = false;
202204 signal (SIGINT , sigexit );
@@ -246,6 +248,17 @@ void icmp_ping(FAR const struct ping_info_s *info)
246248 }
247249#endif
248250
251+ filter = ICMP_SET_FILTER (ICMP_ECHO_REPLY );
252+ ret = setsockopt (priv -> sockfd , IPPROTO_ICMP , ICMP_FILTER ,
253+ & filter , sizeof (filter ));
254+ if (ret < 0 )
255+ {
256+ icmp_callback (& result , ICMP_E_FILTER , errno );
257+ close (priv -> sockfd );
258+ free (priv );
259+ return ;
260+ }
261+
249262 priv -> kickoff = clock ();
250263
251264 memset (& priv -> destaddr , 0 , sizeof (struct sockaddr_in ));
You can’t perform that action at this time.
0 commit comments