Exemple #1
0
void adaptorListFree(SFLAdaptorList *adList)
{
    adaptorListReset(adList);
    my_free(adList->adaptors);
    my_free(adList);
}
Exemple #2
0
  int readInterfaces(HSP *sp)
  {
    
    char *a;
    u_char dest_mac[6];
    struct sockaddr_in *foo;
    if(sp->adaptorList == NULL) sp->adaptorList = adaptorListNew();
    else adaptorListReset(sp->adaptorList);
    
    // Walk the interfaces and collect the non-loopback interfaces so that we
    // have a list of MAC addresses for each interface (usually only 1).
    //
    // May need to come back and run a variation of this where we supply
    // a domain and collect the virtual interfaces for that domain in a
    // similar way.  It looks like we do that by just parsing the numbers
    // out of the interface name.
    
    struct ifaddrs *ifap;
    
    getifaddrs(&ifap);
    for(struct ifaddrs *ifp = ifap; ifp; ifp = ifp->ifa_next) {
      char *devName = ifp->ifa_name;
      if(devName) {
	devName = trimWhitespace(devName);
	// Get the flags for this interface
	int up = (ifp->ifa_flags & IFF_UP) ? YES : NO;
	int loopback = (ifp->ifa_flags & IFF_LOOPBACK) ? YES : NO;
	int promisc =  (ifp->ifa_flags & IFF_PROMISC) ? YES : NO;
	int address_family = ifp->ifa_addr->sa_family;
	if(debug > 1) {
	  myLog(LOG_INFO, "reading interface %s (up=%d, loopback=%d, family=%d)",
		devName,
		up,
		loopback,
		address_family);
	}
	//int hasBroadcast = (ifp->ifa_flags & IFF_BROADCAST);
	//int pointToPoint = (ifp->ifa_flags & IFF_POINTOPOINT);
	
	if(up && !loopback && address_family == AF_INET) {
	  
	  /***** THE NEW WAY ******/
	  
	  find_mac(devName,&dest_mac[0]);
	  SFLAdaptor *adaptor = adaptorListAdd(sp->adaptorList, devName, 
					       (u_char *)&dest_mac); 
	  /*
	    SFLAdaptor *adaptor = adaptorListAdd(sp->adaptorList, devName, 
	    (u_char *)&(ifp->ifa_addr->sa_data)); 
	  */
	  adaptor->promiscuous = promisc;
	  
	  address_family = ifp->ifa_addr->sa_family;
	  
	  if(debug > 1) {
	    myLog(LOG_INFO, "Device: %s",devName);
	    myLog(LOG_INFO, "Address family: %d",address_family);
	  }
	  
	  foo = (struct sockaddr_in *)&ifp->ifa_addr;
	  if (address_family == AF_INET) {
	    
	    a=(char *)&(ifp->ifa_addr->sa_data);
	    a++; a++; // Yep... it really is 2 bytes over 
	    // Only IPV4 below ....
	    memcpy(&adaptor->ipAddr.addr, a, 4);
	    if(debug > 1) {
	      myLog(LOG_INFO, "My IP address = %d.%d.%d.%d", a[0], a[1], a[2], a[3]);
	    }
	  }
	}	  
      }
    }
    updateAdaptorNIO(sp);
    freeifaddrs(ifap);
    return sp->adaptorList->num_adaptors;
    
  }