On Fri, Feb 4, 2011 at 7:45 AM, Adam Stokes <astokes(a)fedoraproject.org> wrote:
- Uses network interface description in place of sigar's
ethX naming scheme. This does not allow for an administrator
to disable/enable the device, but at least gives identifiable
names.
---
include/sigar.h | 2 +-
src/os/win32/win32_sigar.c | 129 ++++++++-----------------------------------
2 files changed, 25 insertions(+), 106 deletions(-)
diff --git a/include/sigar.h b/include/sigar.h
index 48974ed..2f6fefa 100644
--- a/include/sigar.h
+++ b/include/sigar.h
@@ -602,7 +602,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar,
#define SIGAR_IPV6_ADDR_COMPATv4 0x0080
typedef struct {
- char name[16];
+ char *name;
char type[64];
char description[256];
sigar_net_address_t hwaddr;
diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c
index 87076c8..d1b576a 100755
--- a/src/os/win32/win32_sigar.c
+++ b/src/os/win32/win32_sigar.c
@@ -2661,7 +2661,8 @@ static int netif_hash(char *s)
{
int hash = 0;
while (*s) {
Can you explain the reason for the following change?
- hash = 31*hash + *s++;
+ // hash = 31*hash + *s++;
+ hash = 10*hash + *s++;
}
return hash;
}
@@ -2679,16 +2680,6 @@ sigar_net_interface_list_get(sigar_t *sigar,
int i, status;
int lo=0, eth=0, la=0;
This is only temporary right?
- if (!sigar->netif_mib_rows) {
- sigar->netif_mib_rows =
- sigar_netif_cache_new(sigar);
- }
-
- if (!sigar->netif_names) {
- sigar->netif_names =
- sigar_netif_cache_new(sigar);
- }
-
if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) {
return status;
}
@@ -2701,22 +2692,14 @@ sigar_net_interface_list_get(sigar_t *sigar,
}
for (i=0; i<ift->dwNumEntries; i++) {
- char name[16];
- int key;
+ char *name;
MIB_IFROW *ifr = ift->table + i;
- sigar_cache_entry_t *entry;
- if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
- /* special-case */
- sprintf(name, NETIF_LA "%d", la++);
- }
- else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
- sprintf(name, "lo%d", lo++);
- }
- else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
- (ifr->dwType == IF_TYPE_IEEE80211))
+ if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
+ (ifr->dwType == IF_TYPE_IEEE80211) ||
+ (ifr->dwType == MIB_IF_TYPE_LOOPBACK))
{
- sprintf(name, "eth%d", eth++);
+ name = sigar_strdup(ifr->bDescr);
You're going to need to free this somewhere since the existing code
does a memcpy.
}
else {
continue; /*XXX*/
@@ -2726,20 +2709,7 @@ sigar_net_interface_list_get(sigar_t *sigar,
iflist->data[iflist->number++] = sigar_strdup(name);
}
this is also temporary right?
I can't really say much more about the patch unless I know why things
are changing and if the change is temporary or not.
Try using ifdef's for code that you're temporarily disabling rather
than replacing.
- key = netif_hash(name);
- entry = sigar_cache_get(sigar->netif_mib_rows, key);
- if (!entry->value) {
- entry->value = malloc(sizeof(*ifr));
- }
- memcpy(entry->value, ifr, sizeof(*ifr));
-
- /* save dwIndex -> name mapping for use by route_list */
- entry = sigar_cache_get(sigar->netif_names, ifr->dwIndex);
- if (!entry->value) {
- entry->value = sigar_strdup(name);
- }
}
-
return SIGAR_OK;
}
@@ -2788,84 +2758,33 @@ sigar_net_interface_config_get(sigar_t *sigar,
const char *name,
sigar_net_interface_config_t *ifconfig)
{
- MIB_IFROW *ifr;
- MIB_IPADDRROW *ipaddr;
+ IP_ADAPTER_INFO *info;
int status;
- if (!name) {
- return sigar_net_interface_config_primary_get(sigar, ifconfig);
- }
-
- status = get_mib_ifrow(sigar, name, &ifr);
- if (status != SIGAR_OK) {
- return status;
- }
+ status = sigar_get_adapters_info(sigar, &info);
SIGAR_ZERO(ifconfig);
+ ifconfig->name = sigar_strdup(name);
- SIGAR_SSTRCPY(ifconfig->name, name);
-
- ifconfig->mtu = ifr->dwMtu;
-
- sigar_net_address_mac_set(ifconfig->hwaddr,
- ifr->bPhysAddr,
- SIGAR_IFHWADDRLEN);
-
- SIGAR_SSTRCPY(ifconfig->description,
- ifr->bDescr);
-
- if (ifr->dwOperStatus & MIB_IF_OPER_STATUS_OPERATIONAL) {
- ifconfig->flags |= SIGAR_IFF_UP|SIGAR_IFF_RUNNING;
- }
-
- status = sigar_get_netif_ipaddr(sigar,
- ifr->dwIndex,
- &ipaddr);
-
- if (status == SIGAR_OK) {
- sigar_net_address_set(ifconfig->address,
- ipaddr->dwAddr);
-
- sigar_net_address_set(ifconfig->netmask,
- ipaddr->dwMask);
-
- if (ifr->dwType != MIB_IF_TYPE_LOOPBACK) {
- if (ipaddr->dwBCastAddr) {
- long bcast =
- ipaddr->dwAddr & ipaddr->dwMask;
-
- bcast |= ~ipaddr->dwMask;
- ifconfig->flags |= SIGAR_IFF_BROADCAST;
-
- sigar_net_address_set(ifconfig->broadcast,
- bcast);
- }
- }
- }
+ /*
+ while(info) {
+ if(strcmp(name, info->Description) == 0) {
+ sigar_net_address_mac_set(ifconfig->hwaddr,
+ info->Address,
+ SIGAR_IFHWADDRLEN);
- /* hack for MS_LOOPBACK_ADAPTER */
- if (strnEQ(name, NETIF_LA, sizeof(NETIF_LA)-1)) {
- ifr->dwType = MIB_IF_TYPE_LOOPBACK;
- }
+ SIGAR_SSTRCPY(ifconfig->description,
+ info->Description);
- if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
- ifconfig->flags |= SIGAR_IFF_LOOPBACK;
+ sigar_net_address_set(ifconfig->address,
+ info->IpAddressList.IpAddress.String);
- SIGAR_SSTRCPY(ifconfig->type,
- SIGAR_NIC_LOOPBACK);
- }
- else {
- if (ipaddr) {
- ifconfig->flags |= SIGAR_IFF_MULTICAST;
+ sigar_net_address_set(ifconfig->netmask,
+ info->IpAddressList.IpMask.String);
}
-
- SIGAR_SSTRCPY(ifconfig->type,
- SIGAR_NIC_ETHERNET);
+ info = info->Next;
}
-
- sigar_net_interface_ipv6_config_init(ifconfig);
- sigar_net_interface_ipv6_config_find(sigar, ifr->dwIndex, ifconfig);
-
+ */
return SIGAR_OK;
}
--
1.7.4
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari