jdk/src/solaris/native/java/net/NetworkInterface.c
changeset 16870 f35b2bd19761
parent 14342 8435a30053c1
child 17423 1c681c88107c
equal deleted inserted replaced
16869:4adc2d6d2d5a 16870:f35b2bd19761
   116 static jclass ni_ia6cls;
   116 static jclass ni_ia6cls;
   117 static jclass ni_ibcls;
   117 static jclass ni_ibcls;
   118 static jmethodID ni_ia4ctrID;
   118 static jmethodID ni_ia4ctrID;
   119 static jmethodID ni_ia6ctrID;
   119 static jmethodID ni_ia6ctrID;
   120 static jmethodID ni_ibctrID;
   120 static jmethodID ni_ibctrID;
   121 static jfieldID ni_iaaddressID;
       
   122 static jfieldID ni_iafamilyID;
       
   123 static jfieldID ni_ia6ipaddressID;
   121 static jfieldID ni_ia6ipaddressID;
   124 static jfieldID ni_ibaddressID;
   122 static jfieldID ni_ibaddressID;
   125 static jfieldID ni_ib4broadcastID;
   123 static jfieldID ni_ib4broadcastID;
   126 static jfieldID ni_ib4maskID;
   124 static jfieldID ni_ib4maskID;
   127 
   125 
   193     ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress");
   191     ni_ibcls = (*env)->FindClass(env, "java/net/InterfaceAddress");
   194     ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls);
   192     ni_ibcls = (*env)->NewGlobalRef(env, ni_ibcls);
   195     ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
   193     ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
   196     ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
   194     ni_ia6ctrID = (*env)->GetMethodID(env, ni_ia6cls, "<init>", "()V");
   197     ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V");
   195     ni_ibctrID = (*env)->GetMethodID(env, ni_ibcls, "<init>", "()V");
   198     ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
       
   199     ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
       
   200     ni_ia6ipaddressID = (*env)->GetFieldID(env, ni_ia6cls, "ipaddress", "[B");
   196     ni_ia6ipaddressID = (*env)->GetFieldID(env, ni_ia6cls, "ipaddress", "[B");
   201     ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
   197     ni_ibaddressID = (*env)->GetFieldID(env, ni_ibcls, "address", "Ljava/net/InetAddress;");
   202     ni_ib4broadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
   198     ni_ib4broadcastID = (*env)->GetFieldID(env, ni_ibcls, "broadcast", "Ljava/net/Inet4Address;");
   203     ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
   199     ni_ib4maskID = (*env)->GetFieldID(env, ni_ibcls, "maskLength", "S");
   204     ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", "I");
   200     ni_defaultIndexID = (*env)->GetStaticFieldID(env, ni_class, "defaultIndex", "I");
   298     (JNIEnv *env, jclass cls, jobject iaObj) {
   294     (JNIEnv *env, jclass cls, jobject iaObj) {
   299 
   295 
   300     netif *ifs, *curr;
   296     netif *ifs, *curr;
   301 
   297 
   302 #ifdef AF_INET6
   298 #ifdef AF_INET6
   303     int family = (  (*env)->GetIntField(env, iaObj, ni_iafamilyID) == IPv4 ) ? AF_INET : AF_INET6;
   299     int family = (getInetAddress_family(env, iaObj) == IPv4) ? AF_INET : AF_INET6;
   304 #else
   300 #else
   305     int family =  AF_INET;
   301     int family =  AF_INET;
   306 #endif
   302 #endif
   307 
   303 
   308     jobject obj = NULL;
   304     jobject obj = NULL;
   323         while (addrP != NULL) {
   319         while (addrP != NULL) {
   324 
   320 
   325             if (family == addrP->family) {
   321             if (family == addrP->family) {
   326                 if (family == AF_INET) {
   322                 if (family == AF_INET) {
   327                     int address1 = htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr);
   323                     int address1 = htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr);
   328                     int address2 = (*env)->GetIntField(env, iaObj, ni_iaaddressID);
   324                     int address2 = getInetAddress_addr(env, iaObj);
   329 
   325 
   330                     if (address1 == address2) {
   326                     if (address1 == address2) {
   331                         match = JNI_TRUE;
   327                         match = JNI_TRUE;
   332                         break;
   328                         break;
   333                     }
   329                     }
   649         jobject ibObj = NULL;
   645         jobject ibObj = NULL;
   650 
   646 
   651         if (addrP->family == AF_INET) {
   647         if (addrP->family == AF_INET) {
   652             iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
   648             iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
   653             if (iaObj) {
   649             if (iaObj) {
   654                  (*env)->SetIntField(env, iaObj, ni_iaaddressID, htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
   650                  setInetAddress_addr(env, iaObj, htonl(((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
   655             }
   651             }
   656             ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
   652             ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
   657             if (ibObj) {
   653             if (ibObj) {
   658                  (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
   654                  (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
   659                  if (addrP->brdcast) {
   655                  if (addrP->brdcast) {
   660                     jobject ia2Obj = NULL;
   656                     jobject ia2Obj = NULL;
   661                     ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
   657                     ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
   662                     if (ia2Obj) {
   658                     if (ia2Obj) {
   663                        (*env)->SetIntField(env, ia2Obj, ni_iaaddressID,
   659                        setInetAddress_addr(env, ia2Obj, htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
   664                                                                htonl(((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
       
   665                        (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
   660                        (*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
   666                        (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
   661                        (*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
   667                     }
   662                     }
   668                  }
   663                  }
   669                  (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
   664                  (*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);