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

Print this page




  47 /* the initial size of our hostent buffers */
  48 #ifndef NI_MAXHOST
  49 #define NI_MAXHOST 1025
  50 #endif
  51 
  52 
  53 /************************************************************************
  54  * Inet6AddressImpl
  55  */
  56 
  57 /*
  58  * Class:     java_net_Inet6AddressImpl
  59  * Method:    getLocalHostName
  60  * Signature: ()Ljava/lang/String;
  61  */
  62 JNIEXPORT jstring JNICALL
  63 Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
  64     char hostname[NI_MAXHOST+1];
  65 
  66     hostname[0] = '\0';
  67     if (JVM_GetHostName(hostname, MAXHOSTNAMELEN)) {
  68         /* Something went wrong, maybe networking is not setup? */
  69         strcpy(hostname, "localhost");
  70     } else {
  71 #ifdef __linux__
  72         /* On Linux gethostname() says "host.domain.sun.com".  On
  73          * Solaris gethostname() says "host", so extra work is needed.
  74          */
  75 #else
  76         /* Solaris doesn't want to give us a fully qualified domain name.
  77          * We do a reverse lookup to try and get one.  This works
  78          * if DNS occurs before NIS in /etc/resolv.conf, but fails
  79          * if NIS comes first (it still gets only a partial name).
  80          * We use thread-safe system calls.
  81          */
  82 #ifdef AF_INET6
  83         if (NET_addrtransAvailable()) {
  84             struct addrinfo  hints, *res;
  85             int error;
  86 
  87             bzero(&hints, sizeof(hints));




  47 /* the initial size of our hostent buffers */
  48 #ifndef NI_MAXHOST
  49 #define NI_MAXHOST 1025
  50 #endif
  51 
  52 
  53 /************************************************************************
  54  * Inet6AddressImpl
  55  */
  56 
  57 /*
  58  * Class:     java_net_Inet6AddressImpl
  59  * Method:    getLocalHostName
  60  * Signature: ()Ljava/lang/String;
  61  */
  62 JNIEXPORT jstring JNICALL
  63 Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
  64     char hostname[NI_MAXHOST+1];
  65 
  66     hostname[0] = '\0';
  67     if (JVM_GetHostName(hostname, sizeof(hostname))) {
  68         /* Something went wrong, maybe networking is not setup? */
  69         strcpy(hostname, "localhost");
  70     } else {
  71 #ifdef __linux__
  72         /* On Linux gethostname() says "host.domain.sun.com".  On
  73          * Solaris gethostname() says "host", so extra work is needed.
  74          */
  75 #else
  76         /* Solaris doesn't want to give us a fully qualified domain name.
  77          * We do a reverse lookup to try and get one.  This works
  78          * if DNS occurs before NIS in /etc/resolv.conf, but fails
  79          * if NIS comes first (it still gets only a partial name).
  80          * We use thread-safe system calls.
  81          */
  82 #ifdef AF_INET6
  83         if (NET_addrtransAvailable()) {
  84             struct addrinfo  hints, *res;
  85             int error;
  86 
  87             bzero(&hints, sizeof(hints));