~ubuntu-branches/ubuntu/trusty/ntop/trusty

« back to all changes in this revision

Viewing changes to traffic.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2008-06-15 14:38:28 UTC
  • mfrom: (2.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080615143828-oalh84nda2hje4do
Tags: 3:3.3-11
Correction of Polish translation encoding, closes: #479490. Thanks
to Christian Perrier <bubulle@debian.org> for the help.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 1998-2005 Luca Deri <deri@ntop.org>
 
2
 *  Copyright (C) 1998-2007 Luca Deri <deri@ntop.org>
3
3
 *
4
4
 *                          http://www.ntop.org/
5
5
 *
538
538
/* Check if a host can be potentially added the host matrix */
539
539
int isMatrixHost(HostTraffic *host, int actualDeviceId) {
540
540
  if((host->hostIpAddress.hostFamily == AF_INET) /* Only IPv4 addresses are used in the matrix */
541
 
     && (deviceLocalAddress(&host->hostIpAddress, actualDeviceId) || multicastHost(host))
 
541
     && (deviceLocalAddress(&host->hostIpAddress, actualDeviceId, NULL, NULL) || multicastHost(host))
542
542
     && (!broadcastHost(host)))
543
543
    return(1);
544
544
  else
727
727
  else
728
728
    return(0);
729
729
}
 
730
 
 
731
/* ********************************** */
 
732
 
 
733
char* findHostCommunity(u_int32_t host_ip, char *buf, u_short buf_len) {
 
734
  datum key, nextkey;
 
735
  int len = strlen(COMMUNITY_PREFIX);
 
736
 
 
737
 
 
738
  key = gdbm_firstkey(myGlobals.prefsFile);
 
739
  while (key.dptr) {
 
740
    char val[256], localAddresses[1024], *communityName;
 
741
    u_int32_t localNetworks[MAX_NUM_NETWORKS][4]; /* [0]=network, [1]=mask, [2]=broadcast, [3]=mask_v6 */
 
742
    u_short numLocalNetworks = 0, i;
 
743
    
 
744
    if((fetchPrefsValue(key.dptr, val, sizeof(val)) == 0)
 
745
       && (!strncmp(key.dptr, COMMUNITY_PREFIX, len))) {
 
746
      localAddresses[0] = '\0';
 
747
      communityName = (char*)&key.dptr[len];
 
748
 
 
749
      handleAddressLists(val, localNetworks, &numLocalNetworks,
 
750
                         localAddresses, sizeof(localAddresses),
 
751
                         CONST_HANDLEADDRESSLISTS_COMMUNITY);
 
752
 
 
753
      // traceEvent(CONST_TRACE_WARNING, "--> Community %s has %d entries", communityName, numLocalNetworks);
 
754
      for(i=0; i<numLocalNetworks; i++) {
 
755
        if((host_ip & localNetworks[i][1]) == localNetworks[i][0]) {
 
756
          //traceEvent(CONST_TRACE_WARNING, "--> Found community %s [%d]", communityName, numLocalNetworks);
 
757
          snprintf(buf, buf_len, "%s", communityName);
 
758
          return(buf);
 
759
        }
 
760
      }
 
761
    }
 
762
 
 
763
    nextkey = gdbm_nextkey(myGlobals.prefsFile, key);
 
764
    free (key.dptr);
 
765
    key = nextkey;
 
766
  }
 
767
 
 
768
  return(NULL);
 
769
}
 
770
 
 
771
/* ********************************** */
 
772
 
 
773
void setHostCommunity(HostTraffic *el) {
 
774
  char *community, buf[64];
 
775
 
 
776
  if((el == NULL) || (el->hostIpAddress.hostFamily != AF_INET))
 
777
    return; /* Only IPv4 is supported */
 
778
  else if(el->community != NULL)
 
779
    return; /* Already set */
 
780
 
 
781
  community = findHostCommunity(el->hostIpAddress.addr._hostIp4Address.s_addr,
 
782
                                buf, sizeof(buf));
 
783
 
 
784
  if(community)
 
785
    el->community = strdup(community);
 
786
}
 
787