src/windows/native/java/net/NetworkInterface_winXP.c
static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
{
    jobject netifObj;
    jobject name, displayName;
    jobjectArray addrArr, bindsArr, childArr;
    netaddr *addrs;
    jint addr_index;
    int netaddrCount=ifs->naddrs;
    netaddr *netaddrP=ifs->addrs;
    jint bind_index;

    /*
     * Create a NetworkInterface object and populate it
     */
    netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
    name = (*env)->NewStringUTF(env, ifs->name);
    if (ifs->dNameIsUnicode) {
        displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
                                        (jsize)wcslen ((PWCHAR)ifs->displayName));
    } else {
        displayName = (*env)->NewStringUTF(env, ifs->displayName);
    }
    if (netifObj == NULL || name == NULL || displayName == NULL) {
        return NULL;
    }
    (*env)->SetObjectField(env, netifObj, ni_nameID, name);
    (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName);
    (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index);
    /*
     * Get the IP addresses for this interface if necessary
     * Note that 0 is a valid number of addresses.
     */
    if (netaddrCount < 0) {
        netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
        if (netaddrCount == -1) {
            return NULL;
        }
    }

    addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL);
    if (addrArr == NULL) {
        return NULL;
    }

    bindsArr = (*env)->NewObjectArray(env, netaddrCount, ni_ibcls, NULL);
    if (bindsArr == NULL) {
      free_netaddr(netaddrP);
      return NULL;
    }

    addrs = netaddrP;
    addr_index = 0;
    bind_index = 0;
    while (addrs != NULL) {
        jobject iaObj, ia2Obj;
        jobject ibObj = NULL;
        if (addrs->addr.him.sa_family == AF_INET) {
            iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
            if (iaObj == NULL) {
                return NULL;
            }
            /* default ctor will set family to AF_INET */

            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr));

            ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
            if (ibObj == NULL) {
              free_netaddr(netaddrP);
              return NULL;
            }
            (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
            ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
            if (ia2Obj == NULL) {
              free_netaddr(netaddrP);
              return NULL;
            }
            setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr));
            (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
            (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
            (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
        } else /* AF_INET6 */ {
            int scope;
            iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
            if (iaObj) {
                int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
                if (ret == JNI_FALSE) {
                    return NULL;
                }
                scope = addrs->addr.him6.sin6_scope_id;
                if (scope != 0) { /* zero is default value, no need to set */
                    setInet6Address_scopeid(env, iaObj, scope);
                    setInet6Address_scopeifname(env, iaObj, netifObj);
                }
                ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
                if (ibObj == NULL) {
                  free_netaddr(netaddrP);
                  return NULL;
                }
                (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
                (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
                (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
            }
        }
        (*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
        addrs = addrs->next;
        addr_index++;
    }
    (*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr);
    (*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr);

    /*
     * Windows doesn't have virtual interfaces, so child array
     * is always empty.
     */
    childArr = (*env)->NewObjectArray(env, 0, ni_class, NULL);
    if (childArr == NULL) {
      return NULL;
    }
    (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);

    /* return the NetworkInterface */
    return netifObj;
}
/*
 * Create a NetworkInterface object, populate the name and index, and
 * populate the InetAddress array based on the IP addresses for this
 * interface.
 */
Create a NetworkInterface object, populate the name and index, and
populate the InetAddress array based on the IP addresses for this
interface.
Create a NetworkInterface object populate the name and index and populate the InetAddress array based on the IP addresses for this interface .
static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
{
    jobject netifObj;
    jobject name, displayName;
    jobjectArray addrArr, bindsArr, childArr;
    netaddr *addrs;
    jint addr_index;
    int netaddrCount=ifs->naddrs;
    netaddr *netaddrP=ifs->addrs;
    jint bind_index;
    netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
    name = (*env)->NewStringUTF(env, ifs->name);
    if (ifs->dNameIsUnicode) {
        displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
                                        (jsize)wcslen ((PWCHAR)ifs->displayName));
    } else {
        displayName = (*env)->NewStringUTF(env, ifs->displayName);
    }
    if (netifObj == NULL || name == NULL || displayName == NULL) {
        return NULL;
    }
    (*env)->SetObjectField(env, netifObj, ni_nameID, name);
    (*env)->SetObjectField(env, netifObj, ni_displayNameID, displayName);
    (*env)->SetIntField(env, netifObj, ni_indexID, ifs->index);
    if (netaddrCount < 0) {
        netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
        if (netaddrCount == -1) {
            return NULL;
        }
    }
    addrArr = (*env)->NewObjectArray(env, netaddrCount, ni_iacls, NULL);
    if (addrArr == NULL) {
        return NULL;
    }
    bindsArr = (*env)->NewObjectArray(env, netaddrCount, ni_ibcls, NULL);
    if (bindsArr == NULL) {
      free_netaddr(netaddrP);
      return NULL;
    }
    addrs = netaddrP;
    addr_index = 0;
    bind_index = 0;
    while (addrs != NULL) {
        jobject iaObj, ia2Obj;
        jobject ibObj = NULL;
        if (addrs->addr.him.sa_family == AF_INET) {
            iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
            if (iaObj == NULL) {
                return NULL;
            }
            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr));
            ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
            if (ibObj == NULL) {
              free_netaddr(netaddrP);
              return NULL;
            }
            (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
            ia2Obj = (*env)->NewObject(env, ni_ia4cls, ni_ia4Ctor);
            if (ia2Obj == NULL) {
              free_netaddr(netaddrP);
              return NULL;
            }
            setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr));
            (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
            (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
            (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
        } else  {
            int scope;
            iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
            if (iaObj) {
                int ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
                if (ret == JNI_FALSE) {
                    return NULL;
                }
                scope = addrs->addr.him6.sin6_scope_id;
                if (scope != 0) { 
                    setInet6Address_scopeid(env, iaObj, scope);
                    setInet6Address_scopeifname(env, iaObj, netifObj);
                }
                ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
                if (ibObj == NULL) {
                  free_netaddr(netaddrP);
                  return NULL;
                }
                (*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
                (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
                (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
            }
        }
        (*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
        addrs = addrs->next;
        addr_index++;
    }
    (*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr);
    (*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr);
    childArr = (*env)->NewObjectArray(env, 0, ni_class, NULL);
    if (childArr == NULL) {
      return NULL;
    }
    (*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
    return netifObj;
}
static jobject createNetworkInterfaceXP ( JNIEnv * env , netif * ifs ) { jobject netifObj ; jobject name , displayName ; jobjectArray addrArr , bindsArr , childArr ; netaddr * addrs ; jint addr_index ; int netaddrCount = ifs -> naddrs ; netaddr * netaddrP = ifs -> addrs ; jint bind_index ; netifObj = ( * env ) -> NewObject ( env , ni_class , ni_ctor ) ; name = ( * env ) -> NewStringUTF ( env , ifs -> name ) ; if ( ifs -> dNameIsUnicode ) { displayName = ( * env ) -> NewString ( env , ( PWCHAR ) ifs -> displayName , ( jsize ) wcslen ( ( PWCHAR ) ifs -> displayName ) ) ; } else { displayName = ( * env ) -> NewStringUTF ( env , ifs -> displayName ) ; } if ( netifObj == NULL || name == NULL || displayName == NULL ) { return NULL ; } ( * env ) -> SetObjectField ( env , netifObj , ni_nameID , name ) ; ( * env ) -> SetObjectField ( env , netifObj , ni_displayNameID , displayName ) ; ( * env ) -> SetIntField ( env , netifObj , ni_indexID , ifs -> index ) ; if ( netaddrCount < 0 ) { netaddrCount = enumAddresses_win ( env , ifs , & netaddrP ) ; if ( netaddrCount == -1 ) { return NULL ; } } addrArr = ( * env ) -> NewObjectArray ( env , netaddrCount , ni_iacls , NULL ) ; if ( addrArr == NULL ) { return NULL ; } bindsArr = ( * env ) -> NewObjectArray ( env , netaddrCount , ni_ibcls , NULL ) ; if ( bindsArr == NULL ) { free_netaddr ( netaddrP ) ; return NULL ; } addrs = netaddrP ; addr_index = 0 ; bind_index = 0 ; while ( addrs != NULL ) { jobject iaObj , ia2Obj ; jobject ibObj = NULL ; if ( addrs -> addr . him . sa_family == AF_INET ) { iaObj = ( * env ) -> NewObject ( env , ni_ia4cls , ni_ia4Ctor ) ; if ( iaObj == NULL ) { return NULL ; } setInetAddress_addr ( env , iaObj , ntohl ( addrs -> addr . him4 . sin_addr . s_addr ) ) ; ibObj = ( * env ) -> NewObject ( env , ni_ibcls , ni_ibctrID ) ; if ( ibObj == NULL ) { free_netaddr ( netaddrP ) ; return NULL ; } ( * env ) -> SetObjectField ( env , ibObj , ni_ibaddressID , iaObj ) ; ia2Obj = ( * env ) -> NewObject ( env , ni_ia4cls , ni_ia4Ctor ) ; if ( ia2Obj == NULL ) { free_netaddr ( netaddrP ) ; return NULL ; } setInetAddress_addr ( env , ia2Obj , ntohl ( addrs -> brdcast . him4 . sin_addr . s_addr ) ) ; ( * env ) -> SetObjectField ( env , ibObj , ni_ibbroadcastID , ia2Obj ) ; ( * env ) -> SetShortField ( env , ibObj , ni_ibmaskID , addrs -> mask ) ; ( * env ) -> SetObjectArrayElement ( env , bindsArr , bind_index ++ , ibObj ) ; } else { int scope ; iaObj = ( * env ) -> NewObject ( env , ni_ia6cls , ni_ia6ctrID ) ; if ( iaObj ) { int ret = setInet6Address_ipaddress ( env , iaObj , ( jbyte * ) & ( addrs -> addr . him6 . sin6_addr . s6_addr ) ) ; if ( ret == JNI_FALSE ) { return NULL ; } scope = addrs -> addr . him6 . sin6_scope_id ; if ( scope != 0 ) { setInet6Address_scopeid ( env , iaObj , scope ) ; setInet6Address_scopeifname ( env , iaObj , netifObj ) ; } ibObj = ( * env ) -> NewObject ( env , ni_ibcls , ni_ibctrID ) ; if ( ibObj == NULL ) { free_netaddr ( netaddrP ) ; return NULL ; } ( * env ) -> SetObjectField ( env , ibObj , ni_ibaddressID , iaObj ) ; ( * env ) -> SetShortField ( env , ibObj , ni_ibmaskID , addrs -> mask ) ; ( * env ) -> SetObjectArrayElement ( env , bindsArr , bind_index ++ , ibObj ) ; } } ( * env ) -> SetObjectArrayElement ( env , addrArr , addr_index , iaObj ) ; addrs = addrs -> next ; addr_index ++ ; } ( * env ) -> SetObjectField ( env , netifObj , ni_addrsID , addrArr ) ; ( * env ) -> SetObjectField ( env , netifObj , ni_bindsID , bindsArr ) ; childArr = ( * env ) -> NewObjectArray ( env , 0 , ni_class , NULL ) ; if ( childArr == NULL ) { return NULL ; } ( * env ) -> SetObjectField ( env , netifObj , ni_childsID , childArr ) ; return netifObj ; }
Create a NetworkInterface object, populate the name and index, and
 populate the InetAddress array based on the IP addresses for this
 interface.
Create a NetworkInterface object populate the name and index and populate the InetAddress array based on the IP addresses for this interface .
/*
     * Create a NetworkInterface object and populate it
     */ /*
     * Get the IP addresses for this interface if necessary
     * Note that 0 is a valid number of addresses.
     */ /* default ctor will set family to AF_INET */ /* AF_INET6 */ /* zero is default value, no need to set */ /*
     * Windows doesn't have virtual interfaces, so child array
     * is always empty.
     */ /* return the NetworkInterface */