Example #1
0
/**
 *  @details This helper method removes "fake" hosts from IPForensics::hosts_
 *           such as multicast and broadcast addresses.
 */
void IPForensics::clean_hosts(IPv4Address* net, IPv4Address *mask) {
  std::set<Host>::iterator it;
  for (it = hosts_.begin(); it != hosts_.end(); ) {
    Host host = *it;
    bool remove {false};
    if (host.mac().fake() || host.ipv4().fake() || host.ipv6().fake()) {
      remove = true;
    }
    if (!host.ipv4().address().empty() && net != nullptr) {
      if (!host.ipv4().mask(*net, *mask)) {
        remove = true;
      }
    }
    if (remove) {
      hosts_.erase(it++);
    } else {
      ++it;
    }
  }
}
Example #2
0
void IPForensics::update_host(std::set<Host>::iterator it, IPv4Address ipv4,
                              IPv6Address ipv6) {
  Host h = *it;
  if (h.ipv4().address().empty() && !ipv4.address().empty()) {
    h.set_ipv4(ipv4);
  }
  if (h.ipv6().address().empty() && !ipv6.address().empty()) {
    h.set_ipv6(ipv6);
  }
  // replace previous IPv6 address if it is link-local
  if (!h.ipv6().address().empty() && !ipv6.address().empty()) {
    if (h.ipv6().address()[0] == ipf::kLinkLocalIPv6[0] &&
        h.ipv6().address()[1] == ipf::kLinkLocalIPv6[1] &&
        ipv6.address()[0] != ipf::kLinkLocalIPv6[0] &&
        ipv6.address()[1] != ipf::kLinkLocalIPv6[1]) {
      h.set_ipv6(ipv6);
    }
  }
  hosts_.erase(it);
  hosts_.insert(h);
}