Exemple #1
0
/**
 * removes intefaces that are not to be monitored from the list
 *
 * @param head
 * @param monitored_links
 *
 * @return
 */
struct iface * filter_if_list(struct iface *head, volatile struct link_state_notify_t * monitored_links)
{
    struct iface * out = NULL;
    struct iface * tmp = NULL;
    int i;

    while (head!=NULL) {
	int copy = 0;
	for (i=0; i<monitored_links->cnt; i++) {
	    if (head->id == monitored_links->ifindex[i]) {
		copy = 1;
	    }
	}
	if (copy) {
	    tmp = head;
	    head = head->next;

	    tmp->next = out;
	    out = tmp;
	} else {
	    tmp = head;
	    head = head->next;
	    tmp->next = 0;
	    if_list_release(tmp);
	}
    }

    return out;
}
TClntIfaceMgr::TClntIfaceMgr(string xmlFile)
    : TIfaceMgr(xmlFile, false)
{
    struct iface * ptr;
    struct iface * ifaceList;

    this->XmlFile = xmlFile;

    // get interface list
    ifaceList = if_list_get(); // external (C coded) function
    ptr = ifaceList;

    if  (!ifaceList) {
        IsDone = true;
        Log(Crit) << "Unable to read info interfaces. Make sure "
                  << "you are using proper port (i.e. win32 on WindowsXP or 2003)"
                  << " and you have IPv6 support enabled." << LogEnd;
        return;
    }

    while (ptr!=NULL) {
        Log(Notice) << "Detected iface " << ptr->name << "/" << ptr->id
                 // << ", flags=" << ptr->flags
                    << ", MAC=" << this->printMac(ptr->mac, ptr->maclen) << "." << LogEnd;

        SPtr<TIfaceIface> iface = new TClntIfaceIface(ptr->name,ptr->id,
                                                          ptr->flags,
                                                          ptr->mac,
                                                          ptr->maclen,
                                                          ptr->linkaddr,
                                                          ptr->linkaddrcount,
                                                          ptr->globaladdr,
                                                          ptr->globaladdrcount,
                                                          ptr->hardwareType);
        this->IfaceLst.append(iface);

        ptr = ptr->next;
    }
    if_list_release(ifaceList); // allocated in pure C, and so release it there

}