< prev index next >

src/java.base/windows/native/libnet/NetworkInterface_winXP.c

Print this page




 236 
 237 /*
 238  */
 239 int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP)
 240 {
 241     DWORD ret;
 242     IP_ADAPTER_ADDRESSES *ptr, *adapters=NULL;
 243     ULONG len=ipinflen, count=0;
 244     netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr;
 245     int tun=0, net=0;
 246 
 247     *netifPP = NULL;
 248    /*
 249     * Get the IPv4 interfaces. This information is the same
 250     * as what previous JDK versions would return.
 251     */
 252 
 253     ret = enumInterfaces(env, netifPP);
 254     if (ret == -1) {
 255         return -1;




 256     } else {
 257         count = ret;
 258     }
 259 
 260     /* locate the loopback (and the last) interface */
 261     for (nif=*netifPP, last=nif; nif!=NULL; nif=nif->next) {
 262         if (nif->ifType == MIB_IF_TYPE_LOOPBACK) {
 263             loopif = nif;
 264         }
 265         last = nif;
 266     }
 267 
 268     // Retrieve IPv4 addresses with the IP Helper API
 269     curr = *netifPP;
 270     while (curr != NULL) {
 271         netaddr *netaddrP;
 272         ret = enumAddresses_win(env, curr, &netaddrP);
 273         if (ret == -1) {
 274             return -1;



 275         }


 276         curr->addrs = netaddrP;
 277         curr->naddrs += ret;
 278         curr = curr->next;

 279     }
 280 
 281     ret = getAdapters (env, &adapters);
 282     if (ret != ERROR_SUCCESS) {
 283         goto err;
 284     }
 285 
 286     /* Now get the IPv6 information. This includes:
 287      *  (a)  IPv6 information associated with interfaces already found
 288      *  (b)  IPv6 information for IPv6 only interfaces (probably tunnels)
 289      *
 290      * For compatibility with previous releases we use the naming
 291      * information gotten from enumInterfaces() for (a) entries
 292      * However, the index numbers are taken from the new API.
 293      *
 294      * The procedure is to go through the list of adapters returned
 295      * by the new API looking for entries that correspond to IPv4 interfaces
 296      * already found.
 297      */
 298 




 236 
 237 /*
 238  */
 239 int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP)
 240 {
 241     DWORD ret;
 242     IP_ADAPTER_ADDRESSES *ptr, *adapters=NULL;
 243     ULONG len=ipinflen, count=0;
 244     netif *nif=NULL, *dup_nif, *last=NULL, *loopif=NULL, *curr;
 245     int tun=0, net=0;
 246 
 247     *netifPP = NULL;
 248    /*
 249     * Get the IPv4 interfaces. This information is the same
 250     * as what previous JDK versions would return.
 251     */
 252 
 253     ret = enumInterfaces(env, netifPP);
 254     if (ret == -1) {
 255         return -1;
 256     } else if( ret == -2){
 257         if ((*env)->ExceptionCheck(env)) {
 258             (*env)->ExceptionClear(env);
 259         }
 260     } else {
 261         count = ret;
 262     }
 263 
 264     /* locate the loopback (and the last) interface */
 265     for (nif=*netifPP, last=nif; nif!=NULL; nif=nif->next) {
 266         if (nif->ifType == MIB_IF_TYPE_LOOPBACK) {
 267             loopif = nif;
 268         }
 269         last = nif;
 270     }
 271 
 272     // Retrieve IPv4 addresses with the IP Helper API
 273     curr = *netifPP;
 274     while (curr != NULL) {
 275         netaddr *netaddrP;
 276         ret = enumAddresses_win(env, curr, &netaddrP);
 277         if (ret == -1) {
 278             return -1;
 279         } else if (ret == -2) {
 280             if ((*env)->ExceptionCheck(env)) {
 281                 (*env)->ExceptionClear(env);
 282             }
 283             break;
 284         } else{
 285             curr->addrs = netaddrP;
 286             curr->naddrs += ret;
 287             curr = curr->next;
 288         }
 289     }
 290 
 291     ret = getAdapters (env, &adapters);
 292     if (ret != ERROR_SUCCESS) {
 293         goto err;
 294     }
 295 
 296     /* Now get the IPv6 information. This includes:
 297      *  (a)  IPv6 information associated with interfaces already found
 298      *  (b)  IPv6 information for IPv6 only interfaces (probably tunnels)
 299      *
 300      * For compatibility with previous releases we use the naming
 301      * information gotten from enumInterfaces() for (a) entries
 302      * However, the index numbers are taken from the new API.
 303      *
 304      * The procedure is to go through the list of adapters returned
 305      * by the new API looking for entries that correspond to IPv4 interfaces
 306      * already found.
 307      */
 308 


< prev index next >