src/solaris/native/java/net/Inet4AddressImpl.c

Print this page




 364       /*
 365        * create the ICMP request
 366        */
 367       icmp = (struct icmp *) sendbuf;
 368       icmp->icmp_type = ICMP_ECHO;
 369       icmp->icmp_code = 0;
 370       icmp->icmp_id = htons(pid);
 371       icmp->icmp_seq = htons(seq);
 372       seq++;
 373       gettimeofday(&tv, NULL);
 374       memcpy(icmp->icmp_data, &tv, sizeof(tv));
 375       plen = ICMP_ADVLENMIN + sizeof(tv);
 376       icmp->icmp_cksum = 0;
 377       icmp->icmp_cksum = in_cksum((u_short *)icmp, plen);
 378       /*
 379        * send it
 380        */
 381       n = sendto(fd, sendbuf, plen, 0, (struct sockaddr *)him,
 382                  sizeof(struct sockaddr));
 383       if (n < 0 && errno != EINPROGRESS ) {









 384         NET_ThrowNew(env, errno, "Can't send ICMP packet");
 385         close(fd);
 386         return JNI_FALSE;
 387       }
 388 
 389       tmout2 = timeout > 1000 ? 1000 : timeout;
 390       do {
 391         tmout2 = NET_Wait(env, fd, NET_WAIT_READ, tmout2);
 392         if (tmout2 >= 0) {
 393           len = sizeof(sa_recv);
 394           n = recvfrom(fd, recvbuf, sizeof(recvbuf), 0, (struct sockaddr *)&sa_recv, &len);
 395           ip = (struct ip*) recvbuf;
 396           hlen1 = (ip->ip_hl) << 2;
 397           icmp = (struct icmp *) (recvbuf + hlen1);
 398           icmplen = n - hlen1;
 399           /*
 400            * We did receive something, but is it what we were expecting?
 401            * I.E.: A ICMP_ECHOREPLY packet with the proper PID.
 402            */
 403           if (icmplen >= 8 && icmp->icmp_type == ICMP_ECHOREPLY &&




 364       /*
 365        * create the ICMP request
 366        */
 367       icmp = (struct icmp *) sendbuf;
 368       icmp->icmp_type = ICMP_ECHO;
 369       icmp->icmp_code = 0;
 370       icmp->icmp_id = htons(pid);
 371       icmp->icmp_seq = htons(seq);
 372       seq++;
 373       gettimeofday(&tv, NULL);
 374       memcpy(icmp->icmp_data, &tv, sizeof(tv));
 375       plen = ICMP_ADVLENMIN + sizeof(tv);
 376       icmp->icmp_cksum = 0;
 377       icmp->icmp_cksum = in_cksum((u_short *)icmp, plen);
 378       /*
 379        * send it
 380        */
 381       n = sendto(fd, sendbuf, plen, 0, (struct sockaddr *)him,
 382                  sizeof(struct sockaddr));
 383       if (n < 0 && errno != EINPROGRESS ) {
 384 #ifdef __linux__
 385         if (errno == EINVAL) {
 386           /*
 387            * On some Linuxes, when bound to the loopback interface, sendto
 388            * will fail and errno will be set to EINVAL. When that happens,
 389            * don't throw an exception, just return false.
 390            */
 391         } else
 392 #endif /*__linux__ */
 393           NET_ThrowNew(env, errno, "Can't send ICMP packet");
 394         close(fd);
 395         return JNI_FALSE;
 396       }
 397 
 398       tmout2 = timeout > 1000 ? 1000 : timeout;
 399       do {
 400         tmout2 = NET_Wait(env, fd, NET_WAIT_READ, tmout2);
 401         if (tmout2 >= 0) {
 402           len = sizeof(sa_recv);
 403           n = recvfrom(fd, recvbuf, sizeof(recvbuf), 0, (struct sockaddr *)&sa_recv, &len);
 404           ip = (struct ip*) recvbuf;
 405           hlen1 = (ip->ip_hl) << 2;
 406           icmp = (struct icmp *) (recvbuf + hlen1);
 407           icmplen = n - hlen1;
 408           /*
 409            * We did receive something, but is it what we were expecting?
 410            * I.E.: A ICMP_ECHOREPLY packet with the proper PID.
 411            */
 412           if (icmplen >= 8 && icmp->icmp_type == ICMP_ECHOREPLY &&