Esempio n. 1
0
/**
 * begin monitoring of those interfaces
 *
 * @param monitored_links head of the monitored links list
 * @param notify pointer to variable that is going to be modifed if change is detected
 */
void link_state_change_init(volatile struct link_state_notify_t * monitored_links,
                            volatile int * notify)
{
    struct iface * ifacesLst;
    int err;

    /* the same structure will be used for notifying about link-state change */
    notifier = notify;
    changed_links = monitored_links;

    parent_id = pthread_self();
    /** @todo Add actual monitoring here (spawn extra thread or install some handlers, etc.)  */

    ifacesLst = if_list_get();

    ifacesLst = filter_if_list(ifacesLst, monitored_links);

    /* uncomment this section to get information regarding interfaces to be monitored */
    /*
    int i=0;
    printf("About to start monitoring %d interfaces:", monitored_links->cnt);
    for (i=0; i<monitored_links->cnt; i++)
	printf(" %d", monitored_links->ifindex[i]);
    printf("\n");
    */


    err = pthread_create(&ntid, NULL, checkLinkState, (void*)ifacesLst);

    if (err !=0 ){
	printf("process create fail in dibbler/Port-linux/lowlevel-linux-link-state.c.");
	return ;
    }
}
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

}