47 fcntl(fd, F_SETFL, flags); \
48 }
49
50 /*
51 * Inet4AddressImpl
52 */
53
54 /*
55 * Class: java_net_Inet4AddressImpl
56 * Method: getLocalHostName
57 * Signature: ()Ljava/lang/String;
58 */
59 JNIEXPORT jstring JNICALL
60 Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
61 char hostname[NI_MAXHOST + 1];
62
63 hostname[0] = '\0';
64 if (gethostname(hostname, sizeof(hostname)) != 0) {
65 strcpy(hostname, "localhost");
66 } else {
67 #if defined(__solaris__)
68 // try to resolve hostname via nameservice
69 // if it is known but getnameinfo fails, hostname will still be the
70 // value from gethostname
71 struct addrinfo hints, *res;
72
73 // make sure string is null-terminated
74 hostname[NI_MAXHOST] = '\0';
75 memset(&hints, 0, sizeof(hints));
76 hints.ai_flags = AI_CANONNAME;
77 hints.ai_family = AF_INET;
78
79 if (getaddrinfo(hostname, NULL, &hints, &res) == 0) {
80 getnameinfo(res->ai_addr, res->ai_addrlen, hostname, sizeof(hostname),
81 NULL, 0, NI_NAMEREQD);
82 freeaddrinfo(res);
83 }
84 #else
85 // make sure string is null-terminated
86 hostname[NI_MAXHOST] = '\0';
87 #endif
88 }
89 return (*env)->NewStringUTF(env, hostname);
90 }
91
92 /*
93 * Find an internet address for a given hostname. Note that this
94 * code only works for addresses of type INET. The translation
95 * of %d.%d.%d.%d to an address (int) occurs in java now, so the
96 * String "host" shouldn't be a %d.%d.%d.%d string. The only
97 * exception should be when any of the %d are out of range and
98 * we fallback to a lookup.
99 *
100 * Class: java_net_Inet4AddressImpl
101 * Method: lookupAllHostAddr
102 * Signature: (Ljava/lang/String;)[[B
103 */
104 JNIEXPORT jobjectArray JNICALL
105 Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
106 jstring host) {
107 jobjectArray ret = NULL;
|
47 fcntl(fd, F_SETFL, flags); \
48 }
49
50 /*
51 * Inet4AddressImpl
52 */
53
54 /*
55 * Class: java_net_Inet4AddressImpl
56 * Method: getLocalHostName
57 * Signature: ()Ljava/lang/String;
58 */
59 JNIEXPORT jstring JNICALL
60 Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
61 char hostname[NI_MAXHOST + 1];
62
63 hostname[0] = '\0';
64 if (gethostname(hostname, sizeof(hostname)) != 0) {
65 strcpy(hostname, "localhost");
66 } else {
67 // make sure string is null-terminated
68 hostname[NI_MAXHOST] = '\0';
69 }
70 return (*env)->NewStringUTF(env, hostname);
71 }
72
73 /*
74 * Find an internet address for a given hostname. Note that this
75 * code only works for addresses of type INET. The translation
76 * of %d.%d.%d.%d to an address (int) occurs in java now, so the
77 * String "host" shouldn't be a %d.%d.%d.%d string. The only
78 * exception should be when any of the %d are out of range and
79 * we fallback to a lookup.
80 *
81 * Class: java_net_Inet4AddressImpl
82 * Method: lookupAllHostAddr
83 * Signature: (Ljava/lang/String;)[[B
84 */
85 JNIEXPORT jobjectArray JNICALL
86 Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
87 jstring host) {
88 jobjectArray ret = NULL;
|