src/java.base/unix/native/libnet/net_util_md.c
changeset 59243 fb1d9bf1be2b
parent 55375 96c7427456f9
equal deleted inserted replaced
59242:6ba3d8d41135 59243:fb1d9bf1be2b
    71 #endif
    71 #endif
    72 #if defined(__solaris__) && !defined(UDP_EXCLBIND)
    72 #if defined(__solaris__) && !defined(UDP_EXCLBIND)
    73 #define UDP_EXCLBIND            0x0101
    73 #define UDP_EXCLBIND            0x0101
    74 #endif
    74 #endif
    75 
    75 
    76 void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
       
    77 {
       
    78 #ifdef MACOSX
       
    79     static jclass ni_class = NULL;
       
    80     static jfieldID ni_defaultIndexID;
       
    81     if (ni_class == NULL) {
       
    82         jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
       
    83         CHECK_NULL(c);
       
    84         c = (*env)->NewGlobalRef(env, c);
       
    85         CHECK_NULL(c);
       
    86         ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I");
       
    87         CHECK_NULL(ni_defaultIndexID);
       
    88         ni_class = c;
       
    89     }
       
    90     int defaultIndex;
       
    91     struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)him;
       
    92     if (sin6->sin6_family == AF_INET6 && (sin6->sin6_scope_id == 0) &&
       
    93         (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
       
    94          IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))) {
       
    95         defaultIndex = (*env)->GetStaticIntField(env, ni_class,
       
    96                                                  ni_defaultIndexID);
       
    97         sin6->sin6_scope_id = defaultIndex;
       
    98     }
       
    99 #endif
       
   100 }
       
   101 
       
   102 int getDefaultScopeID(JNIEnv *env) {
       
   103     int defaultIndex = 0;
       
   104     static jclass ni_class = NULL;
       
   105     static jfieldID ni_defaultIndexID;
       
   106     if (ni_class == NULL) {
       
   107         jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
       
   108         CHECK_NULL_RETURN(c, 0);
       
   109         c = (*env)->NewGlobalRef(env, c);
       
   110         CHECK_NULL_RETURN(c, 0);
       
   111         ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I");
       
   112         CHECK_NULL_RETURN(ni_defaultIndexID, 0);
       
   113         ni_class = c;
       
   114     }
       
   115     defaultIndex = (*env)->GetStaticIntField(env, ni_class,
       
   116                                              ni_defaultIndexID);
       
   117     return defaultIndex;
       
   118 }
       
   119 
       
   120 #define RESTARTABLE(_cmd, _result) do { \
    76 #define RESTARTABLE(_cmd, _result) do { \
   121     do { \
    77     do { \
   122         _result = _cmd; \
    78         _result = _cmd; \
   123     } while((_result == -1) && (errno == EINTR)); \
    79     } while((_result == -1) && (errno == EINTR)); \
   124 } while(0)
    80 } while(0)
   212             b = mid - 1;
   168             b = mid - 1;
   213         }
   169         }
   214     } while (b >= a);
   170     } while (b >= a);
   215 
   171 
   216     return limit;
   172     return limit;
   217 }
       
   218 #endif
       
   219 
       
   220 #ifdef __linux__
       
   221 static int vinit = 0;
       
   222 static int kernelV24 = 0;
       
   223 static int vinit24 = 0;
       
   224 
       
   225 int kernelIsV24 () {
       
   226     if (!vinit24) {
       
   227         struct utsname sysinfo;
       
   228         if (uname(&sysinfo) == 0) {
       
   229             sysinfo.release[3] = '\0';
       
   230             if (strcmp(sysinfo.release, "2.4") == 0) {
       
   231                 kernelV24 = JNI_TRUE;
       
   232             }
       
   233         }
       
   234         vinit24 = 1;
       
   235     }
       
   236     return kernelV24;
       
   237 }
   173 }
   238 #endif
   174 #endif
   239 
   175 
   240 void
   176 void
   241 NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
   177 NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,