Author: mladen.turk(a)jboss.com
Date: 2007-09-14 04:30:34 -0400 (Fri, 14 Sep 2007)
New Revision: 1029
Modified:
trunk/sight/native/os/linux/netadapter.c
Log:
No need to obtain redundant data for each virtual adapter
Modified: trunk/sight/native/os/linux/netadapter.c
===================================================================
--- trunk/sight/native/os/linux/netadapter.c 2007-09-14 07:54:55 UTC (rev 1028)
+++ trunk/sight/native/os/linux/netadapter.c 2007-09-14 08:30:34 UTC (rev 1029)
@@ -150,6 +150,7 @@
char ip6a[64];
char mask[64];
char badr[64];
+ int virt;
} net_ifc_addr_t;
typedef struct net_ifc_data_t {
@@ -213,18 +214,20 @@
memset(&ifi, 0, sizeof(struct ifreq));
strcpy(ifi.ifr_name, name);
-
- if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
- id->index = ifi.ifr_ifindex;
- else
- id->index = -1;
-
- if (!ioctl(sd, SIOCGIFFLAGS, (char *)&ifi))
- id->flags = ifi.ifr_flags;
- /* Can we have IPV4 without MAC address ? */
- if (!id->maca[0] && !ioctl(sd, SIOCGIFHWADDR, (char *)&ifi))
- make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
+ if (!ca->virt) {
+ if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
+ id->index = ifi.ifr_ifindex;
+ else
+ id->index = -1;
+ if (!ioctl(sd, SIOCGIFFLAGS, (char *)&ifi))
+ id->flags = ifi.ifr_flags;
+ /* Can we have IPV4 without MAC address ? */
+ if (!ioctl(sd, SIOCGIFHWADDR, (char *)&ifi))
+ make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
+ if (!ioctl(sd, SIOCGIFMTU, (char *)&ifi))
+ id->mtu = ifi.ifr_mtu;
+ }
if (!ioctl(sd, SIOCGIFNETMASK, (char *)&ifi)) {
sa = (struct sockaddr_in *)&ifi.ifr_netmask;
@@ -236,8 +239,6 @@
sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
inet_ntop(AF_INET, &sa->sin_addr, ca->badr, 64);
}
- if (!ioctl(sd, SIOCGIFMTU, (char *)&ifi))
- id->mtu = ifi.ifr_mtu;
}
net_ifc_data_t *new_ifc_data(JNIEnv *_E, const char *name,
@@ -251,7 +252,7 @@
THROW_FMARK))) {
return NULL;
}
- if (!(id->addr = cache_new(16))) {
+ if (!(id->addr = cache_new(4))) {
throwAprMemoryException(_E, THROW_FMARK,
apr_get_os_error());
free(id);
@@ -304,7 +305,7 @@
THROW_FMARK))) {
return 0;
}
- if (!(e->ifc = cache_new(16))) {
+ if (!(e->ifc = cache_new(8))) {
throwAprMemoryException(_E, THROW_FMARK,
apr_get_os_error());
free(e);
@@ -335,6 +336,7 @@
char *p, las[128] = "";
char pname[IF_NAMESIZE];
struct sockaddr_in *sa;
+ int is_virtual = 0;
sa = (struct sockaddr_in *)&ifr->ifr_addr;
inet_ntop(AF_INET, &sa->sin_addr, las, 64);
@@ -344,6 +346,7 @@
* Remove everything after colon
*/
*p = '\0';
+ is_virtual = 1;
}
ce = cache_add(e->ifc, pname);
if (!(id = (net_ifc_data_t *)ce->data)) {
@@ -355,6 +358,7 @@
}
ce->data = id;
id->type = AF_INET;
+ ca->virt = is_virtual;
strcpy(ca->ip4a, las);
do_ifrec(id, ca, e->sd, ifr->ifr_name);
}
@@ -365,6 +369,7 @@
free(ifc.ifc_buf);
goto cleanup;
}
+ ca->virt = is_virtual;
strcpy(ca->ip4a, las);
do_ifrec(id, ca, e->sd, ifr->ifr_name);
}