IPv6_addr ipV6IpfixToIpV6(const in6_addr & ipv6_ipfix) { IPv6_addr addr; memcpy(addr.begin(), &ipv6_ipfix, sizeof(ipv6_ipfix)); cout << "[0]" << bin2hexstring(addr.begin(), sizeof(IPv6_addr)) << endl; cout << "[1]" << bin2hexstring(addr.begin(), sizeof(IPv6_addr)) << endl; return addr; }
IPv6_addr ipV6NfDumpToIpV6(const uint64_t * ipv6_parts) { IPv6_addr addr; uint64_t p1 = ipv6_parts[0]; uint64_t p2 = ipv6_parts[1]; memcpy(addr.begin(), &p1, sizeof(uint64_t)); memcpy(addr.begin() + sizeof(uint64_t), &p2, sizeof(uint64_t)); cout << util::bin2hexstring(addr.begin(), sizeof(IPv6_addr)) << endl; return addr; // FIXME: is the byte order correct? ~reto }
/** * Generate a bitmask for the given prefix * * \return IPv6_addr IP with the first prefix bits set to 1 * * \exception std::string Errormessage */ IPv6_addr IPv6_addr::getNetmask(const uint8_t prefix) { if (prefix == 0 || prefix > 128) { stringstream errormsg; errormsg << "ERROR: invalid prefix value: (" << prefix << "). "; errormsg << "Valid prefix lengths are 1..128. For monitoring a single host use 128."; throw errormsg.str(); } IPv6_addr netmask; // all bits are set to 0 uint8_t complete_bytes = prefix / 8; uint8_t additional_bits = prefix % 8; fill_n(netmask.begin(), complete_bytes, numeric_limits<unsigned char>::max()); if (additional_bits) { *(netmask.begin() + complete_bytes + 1) = (char) (1 << (additional_bits - 1)); } return netmask; }
/** * Implements the equals operator * * \param other Reference the the IP address which we should compare to * * \return bool True if both addresses are the same, false if not */ bool IPv6_addr::operator==(const IPv6_addr & other) const { return equal(this->begin(), this->end(), other.begin()); }