8287404: Improve ping times

Reviewed-by: alanb, dfuchs, rhalade
This commit is contained in:
Daniel Jeliński 2022-06-08 15:47:46 +00:00 committed by Henry Jen
parent 1b5d35ad2c
commit c06135b5a6
2 changed files with 4 additions and 4 deletions

View file

@ -346,8 +346,8 @@ ping4(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
struct ip *ip; struct ip *ip;
struct sockaddr_in sa_recv; struct sockaddr_in sa_recv;
jchar pid; jchar pid;
struct timeval tv; struct timeval tv = { 0, 0 };
size_t plen = ICMP_ADVLENMIN + sizeof(tv); const size_t plen = ICMP_MINLEN + sizeof(tv);
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
@ -419,7 +419,7 @@ ping4(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
ip = (struct ip *)recvbuf; ip = (struct ip *)recvbuf;
hlen = ((jint)(unsigned int)(ip->ip_hl)) << 2; hlen = ((jint)(unsigned int)(ip->ip_hl)) << 2;
// check if we received enough data // check if we received enough data
if (n < (jint)(hlen + sizeof(struct icmp))) { if (n < (jint)(hlen + plen)) {
continue; continue;
} }
icmp = (struct icmp *)(recvbuf + hlen); icmp = (struct icmp *)(recvbuf + hlen);

View file

@ -545,7 +545,7 @@ ping6(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
struct icmp6_hdr *icmp6; struct icmp6_hdr *icmp6;
struct sockaddr_in6 sa_recv; struct sockaddr_in6 sa_recv;
jchar pid; jchar pid;
struct timeval tv; struct timeval tv = { 0, 0 };
size_t plen = sizeof(struct icmp6_hdr) + sizeof(tv); size_t plen = sizeof(struct icmp6_hdr) + sizeof(tv);
#if defined(__linux__) #if defined(__linux__)