< prev index next >
src/java.base/unix/native/libnet/NetworkInterface.c
Print this page
@@ -217,10 +217,12 @@
(JNIEnv *env, jclass cls, jstring name)
{
netif *ifs, *curr;
jboolean isCopy;
const char* name_utf;
+ char *colonP;
+ char searchName[IFNAMESIZE];
jobject obj = NULL;
if (name != NULL) {
name_utf = (*env)->GetStringUTFChars(env, name, &isCopy);
} else {
@@ -237,18 +239,36 @@
ifs = enumInterfaces(env);
if (ifs == NULL) {
return NULL;
}
- // search the list of interfaces based on name
+ // search the list of interfaces based on name,
+ // if it is virtual sub interface search with parent first.
+ strncpy(searchName, name_utf, IFNAMESIZE);
+ searchName[IFNAMESIZE - 1] = '\0';
+ colonP = strchr(searchName, ':');
+ if (colonP != NULL) {
+ *colonP = 0;
+ }
curr = ifs;
while (curr != NULL) {
+ if (strcmp(searchName, curr->name) == 0) {
+ break;
+ }
+ curr = curr->next;
+ }
+
+ // search the child list
+ if (colonP != NULL && curr != NULL) {
+ curr = curr->childs;
+ while (curr != NULL) {
if (strcmp(name_utf, curr->name) == 0) {
break;
}
curr = curr->next;
}
+ }
// if found create a NetworkInterface
if (curr != NULL) {
obj = createNetworkInterface(env, curr);
}
< prev index next >