in simulation/src/network/utils/ipv6-address.cc [612:705]
void Ipv6Address::Print (std::ostream& os) const
{
NS_LOG_FUNCTION (this << &os);
// note: part of this function has been adapted from inet_ntop6 Linux function.
// See http://www.net-snmp.org/dev/agent/inet__ntop_8c_source.html
// Author: Paul Vixie, 1996.
if (IsIpv4MappedAddress ())
{
os << "::ffff:"
<< (unsigned int) m_address[12] << "."
<< (unsigned int) m_address[13] << "."
<< (unsigned int) m_address[14] << "."
<< (unsigned int) m_address[15];
return;
}
uint16_t address[8];
uint8_t i;
for (i=0; i<8; i++)
{
address[i] = (uint16_t(m_address[2*i]) << 8) | uint16_t(m_address[2*i+1]);
}
int8_t bestBase = -1;
int8_t bestLen = 0;
int8_t curBase = -1;
int8_t curLen = 0;
for (i=0; i<8; i++)
{
if (address[i] == 0)
{
if (curBase == -1)
{
curBase = i;
curLen = 1;
}
else
{
curLen++;
}
}
else
{
if (curBase != -1)
{
if (bestBase == -1 || curLen > bestLen)
{
bestBase = curBase;
bestLen = curLen;
}
curBase = -1;
}
}
}
if (curBase != -1)
{
if (bestBase == -1 || curLen > bestLen)
{
bestBase = curBase;
bestLen = curLen;
}
}
if (bestBase != -1 && bestLen < 2)
{
bestBase = -1;
}
for (i = 0; i < 8;) {
// Are we inside the best run of 0x00's?
if (i == bestBase)
{
os << ':';
i += bestLen;
continue;
}
// Are we following an initial run of 0x00s or any real hex?
if (i != 0)
{
os << ':';
}
os << std::hex << (unsigned int) address[i];
i++;
}
// Was it a trailing run of 0x00's?
if (bestBase != -1 && (bestBase + bestLen) == 8)
{
os << ':';
}
os << std::dec;
}