48 fcntl(fd, F_SETFL, flags); \
49 }
50
51 /*
52 * Inet6AddressImpl
53 */
54
55 /*
56 * Class: java_net_Inet6AddressImpl
57 * Method: getLocalHostName
58 * Signature: ()Ljava/lang/String;
59 */
60 JNIEXPORT jstring JNICALL
61 Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
62 char hostname[NI_MAXHOST + 1];
63
64 hostname[0] = '\0';
65 if (gethostname(hostname, sizeof(hostname)) != 0) {
66 strcpy(hostname, "localhost");
67 } else {
68 #if defined(__solaris__)
69 // try to resolve hostname via nameservice
70 // if it is known but getnameinfo fails, hostname will still be the
71 // value from gethostname
72 struct addrinfo hints, *res;
73
74 // make sure string is null-terminated
75 hostname[NI_MAXHOST] = '\0';
76 memset(&hints, 0, sizeof(hints));
77 hints.ai_flags = AI_CANONNAME;
78 hints.ai_family = AF_UNSPEC;
79
80 if (getaddrinfo(hostname, NULL, &hints, &res) == 0) {
81 getnameinfo(res->ai_addr, res->ai_addrlen, hostname, sizeof(hostname),
82 NULL, 0, NI_NAMEREQD);
83 freeaddrinfo(res);
84 }
85 #else
86 // make sure string is null-terminated
87 hostname[NI_MAXHOST] = '\0';
88 #endif
89 }
90 return (*env)->NewStringUTF(env, hostname);
91 }
92
93 #if defined(MACOSX)
94 /* also called from Inet4AddressImpl.c */
95 __private_extern__ jobjectArray
96 lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
97 {
98 jobjectArray result = NULL;
99 char myhostname[NI_MAXHOST + 1];
100 struct ifaddrs *ifa = NULL;
101 int familyOrder = 0;
102 int count = 0, i, j;
103 int addrs4 = 0, addrs6 = 0, numV4Loopbacks = 0, numV6Loopbacks = 0;
104 jboolean includeLoopback = JNI_FALSE;
105 jobject name;
106
107 initInetAddressIDs(env);
108 JNU_CHECK_EXCEPTION_RETURN(env, NULL);
|
48 fcntl(fd, F_SETFL, flags); \
49 }
50
51 /*
52 * Inet6AddressImpl
53 */
54
55 /*
56 * Class: java_net_Inet6AddressImpl
57 * Method: getLocalHostName
58 * Signature: ()Ljava/lang/String;
59 */
60 JNIEXPORT jstring JNICALL
61 Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
62 char hostname[NI_MAXHOST + 1];
63
64 hostname[0] = '\0';
65 if (gethostname(hostname, sizeof(hostname)) != 0) {
66 strcpy(hostname, "localhost");
67 } else {
68 // make sure string is null-terminated
69 hostname[NI_MAXHOST] = '\0';
70 }
71 return (*env)->NewStringUTF(env, hostname);
72 }
73
74 #if defined(MACOSX)
75 /* also called from Inet4AddressImpl.c */
76 __private_extern__ jobjectArray
77 lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
78 {
79 jobjectArray result = NULL;
80 char myhostname[NI_MAXHOST + 1];
81 struct ifaddrs *ifa = NULL;
82 int familyOrder = 0;
83 int count = 0, i, j;
84 int addrs4 = 0, addrs6 = 0, numV4Loopbacks = 0, numV6Loopbacks = 0;
85 jboolean includeLoopback = JNI_FALSE;
86 jobject name;
87
88 initInetAddressIDs(env);
89 JNU_CHECK_EXCEPTION_RETURN(env, NULL);
|