mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
icmpv6_ping.c: change socket type from SOCK_DGRAM to SOCK_RAW.
standardize the implementation of ping6 to better comply with socket permissions on certain systems. Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
parent
d2902008fe
commit
9c85568c4f
1 changed files with 17 additions and 1 deletions
|
|
@ -42,6 +42,7 @@
|
|||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/icmp6.h>
|
||||
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/net/icmpv6.h>
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue