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

Print this page




  51 #include <inet/nd.h>
  52 #endif
  53 
  54 #ifdef __linux__
  55 #include <arpa/inet.h>
  56 #include <net/route.h>
  57 #include <sys/utsname.h>
  58 
  59 #ifndef IPV6_FLOWINFO_SEND
  60 #define IPV6_FLOWINFO_SEND      33
  61 #endif
  62 
  63 #endif
  64 
  65 #include "jni_util.h"
  66 #include "jvm.h"
  67 #include "net_util.h"
  68 
  69 #include "java_net_SocketOptions.h"
  70 
  71 /* needed from libsocket on Solaris 8 */
  72 
  73 getaddrinfo_f getaddrinfo_ptr = NULL;
  74 freeaddrinfo_f freeaddrinfo_ptr = NULL;
  75 gai_strerror_f gai_strerror_ptr = NULL;
  76 getnameinfo_f getnameinfo_ptr = NULL;
  77 
  78 /*
  79  * EXCLBIND socket options only on Solaris
  80  */
  81 #if defined(__solaris__) && !defined(TCP_EXCLBIND)
  82 #define TCP_EXCLBIND            0x21
  83 #endif
  84 #if defined(__solaris__) && !defined(UDP_EXCLBIND)
  85 #define UDP_EXCLBIND            0x0101
  86 #endif
  87 
  88 void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
  89 {
  90 #ifdef MACOSX
  91     static jclass ni_class = NULL;
  92     static jfieldID ni_defaultIndexID;
  93     if (ni_class == NULL) {
  94         jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
  95         CHECK_NULL(c);
  96         c = (*env)->NewGlobalRef(env, c);
  97         CHECK_NULL(c);


 417      *  we should also check if the APIs are available.
 418      */
 419     ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton");
 420     close(fd);
 421     if (ipv6_fn == NULL ) {
 422         return JNI_FALSE;
 423     } else {
 424         return JNI_TRUE;
 425     }
 426 #endif /* AF_INET6 */
 427 }
 428 #endif /* DONT_ENABLE_IPV6 */
 429 
 430 void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
 431                                            const char* hostname,
 432                                            int gai_error)
 433 {
 434     int size;
 435     char *buf;
 436     const char *format = "%s: %s";
 437     const char *error_string =
 438         (gai_strerror_ptr == NULL) ? NULL : (*gai_strerror_ptr)(gai_error);
 439     if (error_string == NULL)
 440         error_string = "unknown error";
 441 
 442     size = strlen(format) + strlen(hostname) + strlen(error_string) + 2;
 443     buf = (char *) malloc(size);
 444     if (buf) {
 445         jstring s;
 446         sprintf(buf, format, hostname, error_string);
 447         s = JNU_NewStringPlatform(env, buf);
 448         if (s != NULL) {
 449             jobject x = JNU_NewObjectByName(env,
 450                                             "java/net/UnknownHostException",
 451                                             "(Ljava/lang/String;)V", s);
 452             if (x != NULL)
 453                 (*env)->Throw(env, x);
 454         }
 455         free(buf);
 456     }
 457 }
 458 




  51 #include <inet/nd.h>
  52 #endif
  53 
  54 #ifdef __linux__
  55 #include <arpa/inet.h>
  56 #include <net/route.h>
  57 #include <sys/utsname.h>
  58 
  59 #ifndef IPV6_FLOWINFO_SEND
  60 #define IPV6_FLOWINFO_SEND      33
  61 #endif
  62 
  63 #endif
  64 
  65 #include "jni_util.h"
  66 #include "jvm.h"
  67 #include "net_util.h"
  68 
  69 #include "java_net_SocketOptions.h"
  70 







  71 /*
  72  * EXCLBIND socket options only on Solaris
  73  */
  74 #if defined(__solaris__) && !defined(TCP_EXCLBIND)
  75 #define TCP_EXCLBIND            0x21
  76 #endif
  77 #if defined(__solaris__) && !defined(UDP_EXCLBIND)
  78 #define UDP_EXCLBIND            0x0101
  79 #endif
  80 
  81 void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
  82 {
  83 #ifdef MACOSX
  84     static jclass ni_class = NULL;
  85     static jfieldID ni_defaultIndexID;
  86     if (ni_class == NULL) {
  87         jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
  88         CHECK_NULL(c);
  89         c = (*env)->NewGlobalRef(env, c);
  90         CHECK_NULL(c);


 410      *  we should also check if the APIs are available.
 411      */
 412     ipv6_fn = JVM_FindLibraryEntry(RTLD_DEFAULT, "inet_pton");
 413     close(fd);
 414     if (ipv6_fn == NULL ) {
 415         return JNI_FALSE;
 416     } else {
 417         return JNI_TRUE;
 418     }
 419 #endif /* AF_INET6 */
 420 }
 421 #endif /* DONT_ENABLE_IPV6 */
 422 
 423 void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
 424                                            const char* hostname,
 425                                            int gai_error)
 426 {
 427     int size;
 428     char *buf;
 429     const char *format = "%s: %s";
 430     const char *error_string = gai_strerror(gai_error);

 431     if (error_string == NULL)
 432         error_string = "unknown error";
 433 
 434     size = strlen(format) + strlen(hostname) + strlen(error_string) + 2;
 435     buf = (char *) malloc(size);
 436     if (buf) {
 437         jstring s;
 438         sprintf(buf, format, hostname, error_string);
 439         s = JNU_NewStringPlatform(env, buf);
 440         if (s != NULL) {
 441             jobject x = JNU_NewObjectByName(env,
 442                                             "java/net/UnknownHostException",
 443                                             "(Ljava/lang/String;)V", s);
 444             if (x != NULL)
 445                 (*env)->Throw(env, x);
 446         }
 447         free(buf);
 448     }
 449 }
 450