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

Print this page




  43 #include "java_net_Inet4AddressImpl.h"
  44 
  45 /* the initial size of our hostent buffers */
  46 #define HENT_BUF_SIZE 1024
  47 #define BIG_HENT_BUF_SIZE 10240  /* a jumbo-sized one */
  48 
  49 /************************************************************************
  50  * Inet4AddressImpl
  51  */
  52 
  53 /*
  54  * Class:     java_net_Inet4AddressImpl
  55  * Method:    getLocalHostName
  56  * Signature: ()Ljava/lang/String;
  57  */
  58 JNIEXPORT jstring JNICALL
  59 Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
  60     char hostname[MAXHOSTNAMELEN+1];
  61 
  62     hostname[0] = '\0';
  63     if (JVM_GetHostName(hostname, MAXHOSTNAMELEN)) {
  64         /* Something went wrong, maybe networking is not setup? */
  65         strcpy(hostname, "localhost");
  66     } else {
  67 #ifdef __linux__
  68         /* On Linux gethostname() says "host.domain.sun.com".  On
  69          * Solaris gethostname() says "host", so extra work is needed.
  70          */
  71 #else
  72         /* Solaris doesn't want to give us a fully qualified domain name.
  73          * We do a reverse lookup to try and get one.  This works
  74          * if DNS occurs before NIS in /etc/resolv.conf, but fails
  75          * if NIS comes first (it still gets only a partial name).
  76          * We use thread-safe system calls.
  77          */
  78 #endif /* __linux__ */
  79         struct hostent res, res2, *hp;
  80         // these buffers must be pointer-aligned so they are declared
  81         // with pointer type
  82         char *buf[HENT_BUF_SIZE/(sizeof (char *))];
  83         char *buf2[HENT_BUF_SIZE/(sizeof (char *))];




  43 #include "java_net_Inet4AddressImpl.h"
  44 
  45 /* the initial size of our hostent buffers */
  46 #define HENT_BUF_SIZE 1024
  47 #define BIG_HENT_BUF_SIZE 10240  /* a jumbo-sized one */
  48 
  49 /************************************************************************
  50  * Inet4AddressImpl
  51  */
  52 
  53 /*
  54  * Class:     java_net_Inet4AddressImpl
  55  * Method:    getLocalHostName
  56  * Signature: ()Ljava/lang/String;
  57  */
  58 JNIEXPORT jstring JNICALL
  59 Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
  60     char hostname[MAXHOSTNAMELEN+1];
  61 
  62     hostname[0] = '\0';
  63     if (JVM_GetHostName(hostname, sizeof(hostname))) {
  64         /* Something went wrong, maybe networking is not setup? */
  65         strcpy(hostname, "localhost");
  66     } else {
  67 #ifdef __linux__
  68         /* On Linux gethostname() says "host.domain.sun.com".  On
  69          * Solaris gethostname() says "host", so extra work is needed.
  70          */
  71 #else
  72         /* Solaris doesn't want to give us a fully qualified domain name.
  73          * We do a reverse lookup to try and get one.  This works
  74          * if DNS occurs before NIS in /etc/resolv.conf, but fails
  75          * if NIS comes first (it still gets only a partial name).
  76          * We use thread-safe system calls.
  77          */
  78 #endif /* __linux__ */
  79         struct hostent res, res2, *hp;
  80         // these buffers must be pointer-aligned so they are declared
  81         // with pointer type
  82         char *buf[HENT_BUF_SIZE/(sizeof (char *))];
  83         char *buf2[HENT_BUF_SIZE/(sizeof (char *))];