20 * |
20 * |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 #include <ctype.h> |
26 #include <errno.h> |
26 #include <errno.h> |
|
27 #include <stdlib.h> |
|
28 #include <string.h> |
27 #include <sys/time.h> |
29 #include <sys/time.h> |
28 #include <sys/types.h> |
30 #include <sys/types.h> |
29 #include <sys/socket.h> |
|
30 #include <netinet/in.h> |
31 #include <netinet/in.h> |
31 #include <netdb.h> |
32 #include <netinet/icmp6.h> |
32 #include <string.h> |
33 |
33 #include <strings.h> |
34 #if defined(_ALLBSD_SOURCE) |
34 #include <stdlib.h> |
|
35 #include <ctype.h> |
|
36 #ifdef MACOSX |
|
37 #include <ifaddrs.h> |
35 #include <ifaddrs.h> |
38 #include <net/if.h> |
36 #include <net/if.h> |
39 #include <unistd.h> /* gethostname */ |
|
40 #endif |
37 #endif |
41 |
38 |
42 #include "jvm.h" |
|
43 #include "jni_util.h" |
|
44 #include "net_util.h" |
39 #include "net_util.h" |
45 #ifndef IPV6_DEFS_H |
|
46 #include <netinet/icmp6.h> |
|
47 #endif |
|
48 |
40 |
49 #include "java_net_Inet4AddressImpl.h" |
41 #include "java_net_Inet4AddressImpl.h" |
50 #include "java_net_Inet6AddressImpl.h" |
42 #include "java_net_Inet6AddressImpl.h" |
51 #include "java_net_InetAddress.h" |
43 #include "java_net_InetAddress.h" |
52 |
44 |
502 addr = ((caddr[0]<<24) & 0xff000000); |
494 addr = ((caddr[0]<<24) & 0xff000000); |
503 addr |= ((caddr[1] <<16) & 0xff0000); |
495 addr |= ((caddr[1] <<16) & 0xff0000); |
504 addr |= ((caddr[2] <<8) & 0xff00); |
496 addr |= ((caddr[2] <<8) & 0xff00); |
505 addr |= (caddr[3] & 0xff); |
497 addr |= (caddr[3] & 0xff); |
506 memset((void *) &him4, 0, sizeof(him4)); |
498 memset((void *) &him4, 0, sizeof(him4)); |
507 him4.sin_addr.s_addr = (uint32_t) htonl(addr); |
499 him4.sin_addr.s_addr = htonl(addr); |
508 him4.sin_family = AF_INET; |
500 him4.sin_family = AF_INET; |
509 sa = (struct sockaddr *) &him4; |
501 sa = (struct sockaddr *)&him4; |
510 len = sizeof(him4); |
502 len = sizeof(him4); |
511 } else { |
503 } else { |
512 /* |
504 /* |
513 * For IPv6 address construct a sockaddr_in6 structure. |
505 * For IPv6 address construct a sockaddr_in6 structure. |
514 */ |
506 */ |
515 (*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr); |
507 (*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr); |
516 memset((void *) &him6, 0, sizeof(him6)); |
508 memset((void *)&him6, 0, sizeof(him6)); |
517 memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) ); |
509 memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr)); |
518 him6.sin6_family = AF_INET6; |
510 him6.sin6_family = AF_INET6; |
519 sa = (struct sockaddr *) &him6 ; |
511 sa = (struct sockaddr *)&him6; |
520 len = sizeof(him6) ; |
512 len = sizeof(him6); |
521 } |
513 } |
522 |
514 |
523 error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, |
515 error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD); |
524 NI_NAMEREQD); |
|
525 |
516 |
526 if (!error) { |
517 if (!error) { |
527 ret = (*env)->NewStringUTF(env, host); |
518 ret = (*env)->NewStringUTF(env, host); |
528 CHECK_NULL_RETURN(ret, NULL); |
519 CHECK_NULL_RETURN(ret, NULL); |
529 } |
520 } |