|
reSIProcate/stack
9694
|
Represents a network address. More...
#include <Tuple.hxx>

Classes | |
| class | AnyInterfaceCompare |
| A "less than" comparator for Tuple, for use in map containers etc. More... | |
| class | AnyPortAnyInterfaceCompare |
| A "less than" comparator for Tuple, for use in map containers etc. More... | |
| class | AnyPortCompare |
| A "less than" comparator for Tuple, for use in map containers etc. More... | |
| class | FlowKeyCompare |
Public Member Functions | |
| RESIP_HeapCount (Tuple) | |
| Tuple () | |
| Tuple (const GenericIPAddress &genericAddress, TransportType type=UNKNOWN_TRANSPORT, const Data &targetDomain=Data::Empty) | |
| Tuple (const Data &printableAddress, int port, IpVersion ipVer, TransportType type=UNKNOWN_TRANSPORT, const Data &targetDomain=Data::Empty) | |
| Tuple (const Data &printableAddress, int port, TransportType type, const Data &targetDomain=Data::Empty) | |
| Tuple (const in_addr &pipv4, int pport, TransportType ptype, const Data &targetDomain=Data::Empty) | |
| Tuple (const sockaddr &addr, TransportType ptype, const Data &targetDomain=Data::Empty) | |
| const sockaddr & | getSockaddr () const |
| Retrieve a const binary representation of the socket address for this tuple. | |
| sockaddr & | getMutableSockaddr () |
| Retrieve the binary representation of the socket address for this tuple. | |
| void | setSockaddr (const GenericIPAddress &) |
| Set the internal binary representation of the socket address from the GenericIPAddress. | |
| TransportType | getType () const |
| void | setType (TransportType type) |
| void | setPort (int port) |
| int | getPort () const |
| FlowKey | getFlowKey () const |
| bool | isV4 () const |
| IpVersion | ipVersion () const |
| Returns V4 or V6 as appropriate. | |
| void | setIpVersion (IpVersion version) |
| bool | isAnyInterface () const |
| TRUE if this address is equal to the "INADDR_ANY" value for this address family. | |
| socklen_t | length () const |
| bool | isLoopback () const |
| bool | isPrivateAddress () const |
| bool | operator< (const Tuple &rhs) const |
| Compares TransportType, the binary address, port, and address family of the Tuple. | |
| bool | operator== (const Tuple &rhs) const |
| Compares TransportType, the binary address, port, and address family of the Tuple. | |
| Data | presentationFormat () const |
| Wrapper around the inet_top() method. | |
| GenericIPAddress | toGenericIPAddress () const |
| bool | isEqualWithMask (const Tuple &tuple, short mask, bool ignorePort=false, bool ignoreTransport=false) const |
| compares this tuple with the one passed in for family, port and address equality using the passed in address mask (mask is specified by number of bits) | |
| void | setTargetDomain (const Data &target) |
| Set the domain name this address tuple intends to represent. | |
| const Data & | getTargetDomain () const |
| Get the domain name this address tuple intends to represent. | |
| size_t | hash () const |
| Creates a 32-bit hash based on the contents of this Tuple. | |
Static Public Member Functions | |
| static TransportType | toTransport (const Data &) |
| Converts a string representation of transport type, i.e. | |
| static const Data & | toData (TransportType) |
| Converts the TransportType to a string representation of the transport type, e.g. | |
| static const Data & | toDataLower (TransportType type) |
| static Data | inet_ntop (const Tuple &tuple) |
| Converts the binary socket address to presentation format, via the DnsUtil::inet_ntop() method. | |
| static void | writeBinaryToken (const Tuple &tuple, Data &container, const Data &salt=Data::Empty) |
| static Tuple | makeTupleFromBinaryToken (const Data &binaryToken, const Data &salt=Data::Empty) |
Public Attributes | |
| FlowKey | mFlowKey |
| This is a (largely) opaque key that subclasses of Transport will use to help record/find flows. | |
| TransportKey | transportKey |
| Transport * | transport |
| bool | onlyUseExistingConnection |
| sockaddr | mSockaddr |
| sockaddr_in | m_anonv4 |
| char | pad [28] |
Private Attributes | |
| union { | |
| sockaddr mSockaddr | |
| sockaddr_in m_anonv4 | |
| char pad [28] | |
| }; | |
| TransportType | mTransportType |
| Data | mTargetDomain |
Friends | |
| class | AnyInterfaceCompare |
| class | AnyPortCompare |
| class | AnyPortAnyInterfaceCompare |
| class | FlowKeyCompare |
| class | DnsResult |
| EncodeStream & | operator<< (EncodeStream &strm, const Tuple &tuple) |
Represents a network address.
This includes:
Internally the class is aware of the struct sockaddr/sin_addr/sin6addr binary representation of the address. The sa_family of struct sockaddr is used to keep track of whether a Tuple is representing a an IPv4 or IPv6 address.
Also included are some comparator classes that can be used for containers of Tuple.
| Tuple::Tuple | ( | ) |
Definition at line 34 of file Tuple.cxx.
References mSockaddr.
Referenced by makeTupleFromBinaryToken().
: mFlowKey(0), transportKey(0), transport(0), onlyUseExistingConnection(false), mTransportType(UNKNOWN_TRANSPORT) { sockaddr_in* addr4 = (sockaddr_in*)&mSockaddr; memset(addr4, 0, sizeof(sockaddr_in)); mSockaddr.sa_family = AF_INET; }
| Tuple::Tuple | ( | const GenericIPAddress & | genericAddress, |
| TransportType | type = UNKNOWN_TRANSPORT, |
||
| const Data & | targetDomain = Data::Empty |
||
| ) | [explicit] |
Definition at line 46 of file Tuple.cxx.
References setSockaddr().
: mFlowKey(0), transportKey(0), transport(0), onlyUseExistingConnection(false), mTransportType(type), mTargetDomain(targetDomain) { setSockaddr(genericAddress); }

| Tuple::Tuple | ( | const Data & | printableAddress, |
| int | port, | ||
| IpVersion | ipVer, | ||
| TransportType | type = UNKNOWN_TRANSPORT, |
||
| const Data & | targetDomain = Data::Empty |
||
| ) |
Definition at line 59 of file Tuple.cxx.
References resip::Data::empty(), resip::DnsUtil::inet_pton(), m_anonv4, and resip::V4.
: mFlowKey(0), transportKey(0), transport(0), onlyUseExistingConnection(false), mTransportType(type), mTargetDomain(targetDomain) { if (ipVer == V4) { memset(&m_anonv4, 0, sizeof(m_anonv4)); m_anonv4.sin_family = AF_INET; m_anonv4.sin_port = htons(port); if (printableAddr.empty()) { m_anonv4.sin_addr.s_addr = htonl(INADDR_ANY); } else { DnsUtil::inet_pton( printableAddr, m_anonv4.sin_addr); } } else { #ifdef USE_IPV6 memset(&m_anonv6, 0, sizeof(m_anonv6)); m_anonv6.sin6_family = AF_INET6; m_anonv6.sin6_port = htons(port); if (printableAddr.empty()) { m_anonv6.sin6_addr = in6addr_any; } else { DnsUtil::inet_pton( printableAddr, m_anonv6.sin6_addr); } #else assert(0); #endif } }

| Tuple::Tuple | ( | const Data & | printableAddress, |
| int | port, | ||
| TransportType | type, | ||
| const Data & | targetDomain = Data::Empty |
||
| ) |
Definition at line 106 of file Tuple.cxx.
References resip::DnsUtil::inet_pton(), resip::DnsUtil::isIpV4Address(), and m_anonv4.
: mFlowKey(0), transportKey(0), transport(0), onlyUseExistingConnection(false), mTransportType(ptype), mTargetDomain(targetDomain) { if (DnsUtil::isIpV4Address(printableAddr)) { memset(&m_anonv4, 0, sizeof(m_anonv4)); DnsUtil::inet_pton( printableAddr, m_anonv4.sin_addr); m_anonv4.sin_family = AF_INET; m_anonv4.sin_port = htons(port); } else { #ifdef USE_IPV6 memset(&m_anonv6, 0, sizeof(m_anonv6)); DnsUtil::inet_pton( printableAddr, m_anonv6.sin6_addr); m_anonv6.sin6_family = AF_INET6; m_anonv6.sin6_port = htons(port); #else assert(0); #endif } }

| Tuple::Tuple | ( | const in_addr & | pipv4, |
| int | pport, | ||
| TransportType | ptype, | ||
| const Data & | targetDomain = Data::Empty |
||
| ) |
Definition at line 138 of file Tuple.cxx.
References m_anonv4.
:mFlowKey(0), transportKey(0), transport(0), onlyUseExistingConnection(false), mTransportType(ptype), mTargetDomain(targetDomain) { memset(&m_anonv4, 0, sizeof(sockaddr_in)); m_anonv4.sin_addr = ipv4; m_anonv4.sin_port = htons(port); m_anonv4.sin_family = AF_INET; }
| resip::Tuple::Tuple | ( | const sockaddr & | addr, |
| TransportType | ptype, | ||
| const Data & | targetDomain = Data::Empty |
||
| ) |
| FlowKey resip::Tuple::getFlowKey | ( | ) | const [inline] |
| sockaddr& resip::Tuple::getMutableSockaddr | ( | ) | [inline] |
Retrieve the binary representation of the socket address for this tuple.
Definition at line 109 of file Tuple.hxx.
References mSockaddr.
Referenced by resip::InternalTransport::bind(), resip::TransportSelector::determineSourceInterface(), resip::TcpBaseTransport::processListen(), and resip::UdpTransport::processRxRecv().
{ return mSockaddr; }
| int Tuple::getPort | ( | ) | const |
Definition at line 403 of file Tuple.cxx.
References m_anonv4, and mSockaddr.
Referenced by resip::InternalTransport::bind(), resip::TransportSelector::findTransportBySource(), resip::TransportSelector::findTransportByVia(), resip::Helper::getPortForReply(), resip::Transport::makeSendData(), resip::Transport::port(), resip::StatelessHandler::process(), resip::TransactionState::sendCurrentToWire(), resip::Transport::stampReceived(), resip::TcpTransport::TcpTransport(), resip::TransportSelector::transmit(), resip::UdpTransport::UdpTransport(), and writeBinaryToken().
| const sockaddr& resip::Tuple::getSockaddr | ( | ) | const [inline] |
Retrieve a const binary representation of the socket address for this tuple.
Definition at line 105 of file Tuple.hxx.
References mSockaddr.
Referenced by resip::Transport::boundInterface(), resip::TransportSelector::determineSourceInterface(), inet_ntop(), isEqualWithMask(), resip::TcpBaseTransport::makeOutgoingConnection(), resip::UdpTransport::processRxParse(), and writeBinaryToken().
{ return mSockaddr; }
| const Data& resip::Tuple::getTargetDomain | ( | ) | const [inline] |
Get the domain name this address tuple intends to represent.
Useful with DnsUtil, for example.
Definition at line 239 of file Tuple.hxx.
References mTargetDomain.
Referenced by resip::TupleMarkManager::ListEntry::operator<(), resip::TupleMarkManager::ListEntry::operator==(), and resip::TupleMarkManager::ListEntry::operator>().
{
return mTargetDomain;
}
| TransportType resip::Tuple::getType | ( | ) | const [inline] |
Definition at line 115 of file Tuple.hxx.
References mTransportType.
Referenced by resip::TransportSelector::determineSourceInterface(), resip::TransportSelector::findTransportBySource(), resip::TransportSelector::findTransportByVia(), resip::TransactionState::handleSync(), isEqualWithMask(), resip::TransactionState::makeCancelTransaction(), resip::TransactionState::processClientInvite(), resip::TransactionState::processSipMessageAsNew(), resip::TransactionState::processTransportFailure(), resip::TransactionState::sendCurrentToWire(), resip::TransportSelector::transmit(), and writeBinaryToken().
{ return mTransportType; }
| size_t Tuple::hash | ( | ) | const |
Creates a 32-bit hash based on the contents of this Tuple.
Definition at line 673 of file Tuple.cxx.
References resip::Data::hash(), mSockaddr, mTransportType, and resip::Data::Share.
Referenced by main().
{
// !dlb! do not include the connection
#ifdef USE_IPV6
if (mSockaddr.sa_family == AF_INET6)
{
const sockaddr_in6& in6 =
reinterpret_cast<const sockaddr_in6&>(mSockaddr);
return size_t(Data(Data::Share, (const char *)&in6.sin6_addr.s6_addr, sizeof(in6.sin6_addr.s6_addr)).hash() +
5*in6.sin6_port +
25*mTransportType);
}
else
#endif
{
const sockaddr_in& in4 =
reinterpret_cast<const sockaddr_in&>(mSockaddr);
return size_t(in4.sin_addr.s_addr +
5*in4.sin_port +
25*mTransportType);
}
}

Converts the binary socket address to presentation format, via the DnsUtil::inet_ntop() method.
Definition at line 719 of file Tuple.cxx.
References getSockaddr(), and isV4().
Referenced by resip::InternalTransport::bind(), resip::DnsResult::next(), presentationFormat(), resip::Transport::stampReceived(), resip::TransportSelector::transmit(), and resip::Transport::Transport().
{
#ifdef USE_IPV6
if (!tuple.isV4())
{
const sockaddr_in6& addr = reinterpret_cast<const sockaddr_in6&>(tuple.getSockaddr());
return DnsUtil::inet_ntop(addr.sin6_addr);
}
else
#endif
{
const sockaddr_in& addr = reinterpret_cast<const sockaddr_in&>(tuple.getSockaddr());
return DnsUtil::inet_ntop(addr.sin_addr);
}
}

| IpVersion Tuple::ipVersion | ( | ) | const |
Returns V4 or V6 as appropriate.
Definition at line 474 of file Tuple.cxx.
References mSockaddr, resip::V4, and resip::V6.
Referenced by resip::TransportSelector::findTransportBySource(), resip::TransportSelector::findTransportByVia(), resip::Transport::ipVersion(), isLoopback(), isPrivateAddress(), resip::TransportSelector::transmit(), and writeBinaryToken().
| bool Tuple::isAnyInterface | ( | ) | const |
TRUE if this address is equal to the "INADDR_ANY" value for this address family.
Definition at line 422 of file Tuple.cxx.
References isV4(), and m_anonv4.
Referenced by resip::TransportSelector::addTransportInternal(), resip::TransportSelector::determineSourceInterface(), resip::TransportSelector::findTransportByVia(), and resip::TransportSelector::transmit().
{
if (isV4())
{
return m_anonv4.sin_addr.s_addr == htonl(INADDR_ANY);
}
#if defined (USE_IPV6)
else
{
return memcmp(&m_anonv6.sin6_addr, &in6addr_any, sizeof(in6_addr)) == 0;
}
#else
return false;
#endif
}

| bool Tuple::isEqualWithMask | ( | const Tuple & | tuple, |
| short | mask, | ||
| bool | ignorePort = false, |
||
| bool | ignoreTransport = false |
||
| ) | const |
compares this tuple with the one passed in for family, port and address equality using the passed in address mask (mask is specified by number of bits)
Definition at line 737 of file Tuple.cxx.
References getSockaddr(), getType(), and mSockaddr.
Referenced by isLoopback(), isPrivateAddress(), and main().
{
if(ignoreTransport || getType() == compare.getType()) // check if transport type matches
{
if (mSockaddr.sa_family == compare.getSockaddr().sa_family && mSockaddr.sa_family == AF_INET) // v4
{
sockaddr_in* addr1 = (sockaddr_in*)&mSockaddr;
sockaddr_in* addr2 = (sockaddr_in*)&compare.getSockaddr();
return ((ignorePort || addr1->sin_port == addr2->sin_port) &&
(addr1->sin_addr.s_addr & htonl((0xFFFFFFFF << (32 - mask)))) ==
(addr2->sin_addr.s_addr & htonl((0xFFFFFFFF << (32 - mask)))));
}
#ifdef USE_IPV6
else if (mSockaddr.sa_family == compare.getSockaddr().sa_family && mSockaddr.sa_family == AF_INET6) // v6
{
sockaddr_in6* addr1 = (sockaddr_in6*)&mSockaddr;
sockaddr_in6* addr2 = (sockaddr_in6*)&compare.getSockaddr();
if(ignorePort || addr1->sin6_port == addr2->sin6_port)
{
unsigned long mask6part;
unsigned long temp;
bool match=true;
for(int i = 3; i >= 0; i--)
{
if(mask <= 32*i)
{
mask6part = 0;
}
else
{
temp = mask - 32*i;
if(temp >= 32)
{
mask6part = 0xffffffff;
}
else
{
mask6part = 0xffffffff << (32 - temp);
}
}
#ifdef WIN32
if((*((unsigned long*)&addr1->sin6_addr.u.Word[i*2]) & htonl(mask6part)) !=
(*((unsigned long*)&addr2->sin6_addr.u.Word[i*2]) & htonl(mask6part)))
#elif defined(sun)
// sun has no s6_addr16
if((*((unsigned long*)&addr1->sin6_addr._S6_un._S6_u32[i]) & htonl(mask6part)) !=
(*((unsigned long*)&addr2->sin6_addr._S6_un._S6_u32[i]) & htonl(mask6part)))
#elif defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
// bsd has no s6_addr16
if((*((unsigned long*)&addr1->sin6_addr.__u6_addr.__u6_addr32[i]) & htonl(mask6part)) !=
(*((unsigned long*)&addr2->sin6_addr.__u6_addr.__u6_addr32[i]) & htonl(mask6part)))
#else
if((*((unsigned long*)&addr1->sin6_addr.s6_addr16[i*2]) & htonl(mask6part)) !=
(*((unsigned long*)&addr2->sin6_addr.s6_addr16[i*2]) & htonl(mask6part)))
#endif
{
match=false;
break;
}
}
if(match)
{
return true;
}
}
}
#endif
}
return false;
}

| bool Tuple::isLoopback | ( | ) | const |
Definition at line 440 of file Tuple.cxx.
References ipVersion(), isEqualWithMask(), loopbackv4, resip::V4, and resip::V6.
Referenced by resip::TransportSelector::findTransportBySource(), isPrivateAddress(), and main().
{
if(ipVersion()==V4)
{
return isEqualWithMask(loopbackv4,8,true,true);
}
else if (ipVersion()==V6)
{
#ifdef USE_IPV6
#if defined(__linux__) || defined(__APPLE__) || defined(WIN32)
return IN6_IS_ADDR_LOOPBACK(&(m_anonv6.sin6_addr)) != 0;
#else
return ((*(const __uint32_t *)(const void *)(&(m_anonv6.sin6_addr.s6_addr[0])) == 0) &&
(*(const __uint32_t *)(const void *)(&(m_anonv6.sin6_addr.s6_addr[4])) == 0) &&
(*(const __uint32_t *)(const void *)(&(m_anonv6.sin6_addr.s6_addr[8])) == 0) &&
(*(const __uint32_t *)(const void *)(&(m_anonv6.sin6_addr.s6_addr[12])) == ntohl(1)));
#endif
#endif
}
else
{
assert(0);
}
return false;
}

| bool Tuple::isPrivateAddress | ( | ) | const |
Definition at line 488 of file Tuple.cxx.
References ipVersion(), isEqualWithMask(), isLoopback(), resip::V4, v4privateaddrbase1, v4privateaddrbase2, v4privateaddrbase3, and resip::V6.
Referenced by main().
{
if(ipVersion()==V4)
{
// RFC 1918
return isEqualWithMask(v4privateaddrbase1,8,true,true) || // 10.0.0.0 - 10.255.255.255 (10/8 prefix)
isEqualWithMask(v4privateaddrbase2,12,true,true) || // 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
isEqualWithMask(v4privateaddrbase3,16,true,true) || // 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
isLoopback();
}
#ifdef USE_IPV6
else if (ipVersion()==V6)
{
// RFC 4193
// ?slg? should we look specifically for ipv4 mapped/compatible address and apply V4 rules to them?
return isEqualWithMask(v6privateaddrbase,7,true,true) || // fc00::/7
isLoopback();
}
#endif
else
{
assert(0);
}
return false;
}

| bool Tuple::isV4 | ( | ) | const |
Definition at line 468 of file Tuple.cxx.
References mSockaddr.
Referenced by resip::TransportSelector::determineSourceInterface(), inet_ntop(), isAnyInterface(), resip::Transport::isV4(), resip::Transport::operator==(), presentationFormat(), and toGenericIPAddress().
{
return mSockaddr.sa_family == AF_INET;
}
| socklen_t Tuple::length | ( | ) | const |
Definition at line 516 of file Tuple.cxx.
References mSockaddr.
Referenced by resip::InternalTransport::bind(), resip::TransportSelector::determineSourceInterface(), resip::TcpBaseTransport::makeOutgoingConnection(), resip::Transport::operator==(), resip::TcpBaseTransport::processListen(), and resip::UdpTransport::processRxRecv().
| Tuple Tuple::makeTupleFromBinaryToken | ( | const Data & | binaryToken, |
| const Data & | salt = Data::Empty |
||
| ) | [static] |
Definition at line 279 of file Tuple.cxx.
References resip::Data::data(), DebugLog, resip::Data::empty(), resip::Data::Empty, resip::MAX_TRANSPORT, mFlowKey, onlyUseExistingConnection, resip::Data::Share, resip::Data::size(), transportKey, Tuple(), type, resip::V4, and resip::V6.
Referenced by main().
{
// To check if size is valid, we first need the IP version, so make sure the token is at least
// the size of an IPv4 token
if(binaryFlowToken.size()<16)
{
// !bwc! Should not assert here, since this sort of thing
// can come off the wire easily.
// TODO Throw an exception here?
DebugLog(<<"binary flow token was too small: " << binaryFlowToken.size());
return Tuple();
}
const UInt32* rawToken=reinterpret_cast<const UInt32*>(binaryFlowToken.data());
FlowKey mFlowKey=rawToken[0];
TransportKey transportKey=rawToken[1];
IpVersion version = (rawToken[2] & 0x00000001 ? V6 : V4);
bool isRealFlow = (rawToken[2] & 0x00000010 ? true : false);
UInt8 temp = (TransportType)((rawToken[2] & 0x00000F00) >> 8);
if(temp >= MAX_TRANSPORT)
{
DebugLog(<<"Garbage transport type in flow token: " << temp );
return Tuple();
}
TransportType type = (TransportType)temp;
UInt16 port= (rawToken[2] >> 16);
// Now that we have the version we can do a more accurate check on the size
if(!((version==V4 && salt.empty() && binaryFlowToken.size()==16) ||
(version==V4 && !salt.empty() && binaryFlowToken.size()==48) ||
(version==V6 && salt.empty() && binaryFlowToken.size()==28) ||
(version==V6 && !salt.empty() && binaryFlowToken.size()==60)))
{
DebugLog(<<"Binary flow token is the wrong size for its IP version.");
return Tuple();
}
// If salt is specified, validate HMAC
if(!salt.empty())
{
unsigned int tokenSizeLessHMAC = version == V4 ? 16 : 28;
Data flowTokenLessHMAC(Data::Share, binaryFlowToken.data(), tokenSizeLessHMAC);
Data flowTokenHMAC(Data::Share, binaryFlowToken.data()+tokenSizeLessHMAC, 32);
MD5Stream ms;
ms << flowTokenLessHMAC << salt;
if(ms.getHex() != flowTokenHMAC)
{
DebugLog(<<"Binary flow token has invalid HMAC, not our token");
return Tuple();
}
}
if(version==V6)
{
#ifdef USE_IPV6
in6_addr address;
assert(sizeof(address)==16);
memcpy(&address,&rawToken[3],16);
Tuple result(address,port,type);
#else
Tuple result(resip::Data::Empty, port, type);
#endif
result.mFlowKey=(FlowKey)mFlowKey;
result.transportKey = (TransportKey)transportKey;
result.onlyUseExistingConnection=isRealFlow;
return result;
}
in_addr address;
assert(sizeof(address)==4);
memcpy(&address,&rawToken[3],4);
Tuple result(address,port,type);
result.mFlowKey=(FlowKey)mFlowKey;
result.transportKey = (TransportKey)transportKey;
result.onlyUseExistingConnection=isRealFlow;
return result;
}

| bool Tuple::operator< | ( | const Tuple & | rhs | ) | const |
Compares TransportType, the binary address, port, and address family of the Tuple.
Definition at line 565 of file Tuple.cxx.
References m_anonv4, mSockaddr, and mTransportType.
{
if (mTransportType < rhs.mTransportType)
{
return true;
}
else if (mTransportType > rhs.mTransportType)
{
return false;
}
else if (mSockaddr.sa_family == AF_INET && rhs.mSockaddr.sa_family == AF_INET)
{
int c=memcmp(&m_anonv4.sin_addr,
&rhs.m_anonv4.sin_addr,
sizeof(in_addr));
if (c < 0)
{
return true;
}
else if (c > 0)
{
return false;
}
else if (m_anonv4.sin_port < rhs.m_anonv4.sin_port)
{
return true;
}
else
{
return false;
}
}
#ifdef USE_IPV6
else if (mSockaddr.sa_family == AF_INET6 &&
rhs.mSockaddr.sa_family == AF_INET6)
{
int c = memcmp(&m_anonv6.sin6_addr,
&rhs.m_anonv6.sin6_addr,
sizeof(in6_addr));
if (c < 0)
{
return true;
}
else if (c > 0)
{
return false;
}
else if (m_anonv6.sin6_port < rhs.m_anonv6.sin6_port)
{
return true;
}
else
{
return false;
}
}
else if (mSockaddr.sa_family == AF_INET6 &&
rhs.mSockaddr.sa_family == AF_INET)
{
return true;
}
else if (mSockaddr.sa_family == AF_INET &&
rhs.mSockaddr.sa_family == AF_INET6)
{
return false;
}
#endif
else
{
//assert(0);
return false;
}
}
| bool Tuple::operator== | ( | const Tuple & | rhs | ) | const |
Compares TransportType, the binary address, port, and address family of the Tuple.
Definition at line 534 of file Tuple.cxx.
References m_anonv4, mSockaddr, and mTransportType.
{
if (mSockaddr.sa_family == rhs.mSockaddr.sa_family)
{
if (mSockaddr.sa_family == AF_INET) // v4
{
return (m_anonv4.sin_port == rhs.m_anonv4.sin_port &&
mTransportType == rhs.mTransportType &&
memcmp(&m_anonv4.sin_addr, &rhs.m_anonv4.sin_addr, sizeof(in_addr)) == 0);
}
else // v6
{
#ifdef USE_IPV6
return (m_anonv6.sin6_port == rhs.m_anonv6.sin6_port &&
mTransportType == rhs.mTransportType &&
memcmp(&m_anonv6.sin6_addr, &rhs.m_anonv6.sin6_addr, sizeof(in6_addr)) == 0);
#else
assert(0);
return false;
#endif
}
}
else
{
return false;
}
// !dlb! don't include connection
}
| Data Tuple::presentationFormat | ( | ) | const |
Wrapper around the inet_top() method.
Definition at line 363 of file Tuple.cxx.
References inet_ntop(), and isV4().
{
#ifdef USE_IPV6
if (isV4())
{
return Tuple::inet_ntop(*this);
}
else if (IN6_IS_ADDR_V4MAPPED(&m_anonv6.sin6_addr))
{
return DnsUtil::inet_ntop(*(reinterpret_cast<const in_addr*>(
(reinterpret_cast<const unsigned char*>(&m_anonv6.sin6_addr) + 12))));
}
else
{
return Tuple::inet_ntop(*this);
}
#else
return Tuple::inet_ntop(*this);
#endif
}

| resip::Tuple::RESIP_HeapCount | ( | Tuple | ) |
| void resip::Tuple::setIpVersion | ( | IpVersion | version | ) |
| void Tuple::setPort | ( | int | port | ) |
Definition at line 386 of file Tuple.cxx.
References m_anonv4, and mSockaddr.
Referenced by resip::TransportSelector::determineSourceInterface(), resip::TransportSelector::findTransportByVia(), resip::Helper::getClientPublicAddress(), resip::TransactionState::processSipMessageAsNew(), resip::TransactionState::sendCurrentToWire(), and resip::TransportSelector::transmit().
| void Tuple::setSockaddr | ( | const GenericIPAddress & | addr | ) |
Set the internal binary representation of the socket address from the GenericIPAddress.
Definition at line 202 of file Tuple.cxx.
References resip::GenericIPAddress::isVersion4(), m_anonv4, and resip::GenericIPAddress::v4Address.
Referenced by resip::TransportSelector::determineSourceInterface(), and Tuple().
{
if (addr.isVersion4())
{
m_anonv4 = addr.v4Address;
}
else
#ifdef USE_IPV6
{
m_anonv6 = addr.v6Address;
}
#else
{
assert(0);
}
#endif
}

| void resip::Tuple::setTargetDomain | ( | const Data & | target | ) | [inline] |
Set the domain name this address tuple intends to represent.
Definition at line 232 of file Tuple.hxx.
References mTargetDomain.
{
mTargetDomain = target;
}
| void resip::Tuple::setType | ( | TransportType | type | ) | [inline] |
Definition at line 116 of file Tuple.hxx.
References mTransportType, and type.
Referenced by resip::TcpTransport::TcpTransport(), and resip::UdpTransport::UdpTransport().
{ mTransportType = type ;}
| const Data & Tuple::toData | ( | TransportType | type | ) | [static] |
Converts the TransportType to a string representation of the transport type, e.g.
"TCP"
Definition at line 707 of file Tuple.cxx.
Referenced by resip::SipStack::addTransport(), and resip::InternalTransport::socket().
{
return resip::toData(type); // TransportTypes.hxx
}
| const Data & Tuple::toDataLower | ( | TransportType | type | ) | [static] |
Definition at line 713 of file Tuple.cxx.
{
return resip::toDataLower(type); // TransportTypes.hxx
}
| GenericIPAddress Tuple::toGenericIPAddress | ( | ) | const |
Definition at line 935 of file Tuple.cxx.
References isV4(), and m_anonv4.
Referenced by resip::TransportSelector::determineSourceInterface(), and main().
{
if (isV4())
{
return GenericIPAddress(m_anonv4);
}
else
#ifdef USE_IPV6
{
return GenericIPAddress(m_anonv6);
}
#else
{
assert(0);
return m_anonv4; //bogus
}
#endif
}

| TransportType Tuple::toTransport | ( | const Data & | transportName | ) | [static] |
Converts a string representation of transport type, i.e.
"UDP" to a TransportType
Definition at line 701 of file Tuple.cxx.
References resip::toTransportType().
Referenced by resip::Helper::getClientPublicAddress(), resip::DnsResult::lookupInternal(), resip::StatelessHandler::process(), and simpleTupleForUri().
{
return resip::toTransportType(transportName); // TransportTypes.hxx
};

| void Tuple::writeBinaryToken | ( | const Tuple & | tuple, |
| resip::Data & | container, | ||
| const Data & | salt = Data::Empty |
||
| ) | [static] |
Definition at line 221 of file Tuple.cxx.
References resip::Data::append(), resip::Data::clear(), resip::Data::empty(), resip::MD5Stream::getHex(), getPort(), getSockaddr(), getType(), ipVersion(), mFlowKey, onlyUseExistingConnection, resip::Data::reserve(), transportKey, and resip::V6.
Referenced by main().
{
// .bwc. Maybe should just write the raw sockaddr into a buffer, and tack
// on the flowid and onlyUseExistingConnection flag. Would require 10 extra
// bytes for V6, and 14 extra bytes for V4.
// V6: sin6_len(1), sin6_flowinfo(4), flowId(4), onlyUseExistingConnection(1)
// V4: sin_family(2 instead of 1), sin_zero(8), flowId(4), onlyUseExistingConnection(1)
UInt32 rawToken[7];
memset(&rawToken, 0, 28);
rawToken[0] = tuple.mFlowKey;
rawToken[1] = tuple.transportKey;
// 0xXXXX0000
rawToken[2] += (tuple.getPort() << 16);
// 0x0000XX00
rawToken[2] += (tuple.getType() << 8);
// 0x000000X0
if(tuple.onlyUseExistingConnection)
{
rawToken[2] += 0x00000010;
}
#ifdef USE_IPV6
if(tuple.ipVersion()==V6)
{
// 0x0000000X
rawToken[2] += 0x00000001;
in6_addr address = reinterpret_cast<const sockaddr_in6&>(tuple.getSockaddr()).sin6_addr;
assert(sizeof(address)==16);
memcpy(&rawToken[3],&address,16);
}
else
#endif
{
in_addr address = reinterpret_cast<const sockaddr_in&>(tuple.getSockaddr()).sin_addr;
assert(sizeof(address)==4);
memcpy(&rawToken[3],&address,4);
}
container.clear();
container.reserve(((tuple.ipVersion()==V6) ? 28 : 16) + (salt.empty() ? 0 : 32));
container.append((char*)&rawToken[0],(tuple.ipVersion()==V6) ? 28 : 16);
if(!salt.empty())
{
// TODO - potentially use SHA1 HMAC if USE_SSL is defined for stronger encryption
MD5Stream ms;
ms << container << salt;
container += ms.getHex();
}
}

friend class AnyInterfaceCompare [friend] |
friend class AnyPortAnyInterfaceCompare [friend] |
friend class AnyPortCompare [friend] |
friend class FlowKeyCompare [friend] |
| EncodeStream& operator<< | ( | EncodeStream & | strm, |
| const Tuple & | tuple | ||
| ) | [friend] |
union { ... } [private] |
| sockaddr_in resip::Tuple::m_anonv4 |
Definition at line 253 of file Tuple.hxx.
Referenced by getPort(), isAnyInterface(), resip::Tuple::AnyInterfaceCompare::operator()(), resip::Tuple::AnyPortCompare::operator()(), operator<(), operator==(), setPort(), setSockaddr(), toGenericIPAddress(), and Tuple().
| FlowKey resip::Tuple::mFlowKey |
This is a (largely) opaque key that subclasses of Transport will use to help record/find flows.
For UDP and DTLS, this is just the FD, and the rest of the information about the flow is carried in the Tuple. For TCP and TLS, the FD of the connection is used. For protocols where using the FD would not be appropriate (SCTP), the transport may use whatever method to generate these it likes. (It is highly recommended that these ids are unique across all instances of a transport type)
Definition at line 177 of file Tuple.hxx.
Referenced by resip::ConnectionManager::addConnection(), resip::Connection::Connection(), resip::ConnectionManager::findConnection(), resip::TransportSelector::findTransportByVia(), resip::ConnectionTerminated::getFlowKey(), resip::KeepAlivePong::getFlowKey(), resip::ConnectionBase::getFlowKey(), getFlowKey(), resip::Connection::getSocket(), main(), makeTupleFromBinaryToken(), resip::Tuple::FlowKeyCompare::operator()(), resip::StatelessHandler::process(), resip::TcpBaseTransport::processAllWriteRequests(), resip::UdpTransport::processRxParse(), resip::ConnectionManager::removeConnection(), resip::TransactionState::sendCurrentToWire(), resip::SipStack::sendOverExistingConnection(), resip::TransportSelector::transmit(), resip::UdpTransport::UdpTransport(), writeBinaryToken(), and resip::Connection::~Connection().
| sockaddr resip::Tuple::mSockaddr |
Definition at line 252 of file Tuple.hxx.
Referenced by getMutableSockaddr(), getPort(), getSockaddr(), hash(), ipVersion(), isEqualWithMask(), isV4(), length(), resip::Tuple::AnyInterfaceCompare::operator()(), resip::Tuple::AnyPortCompare::operator()(), resip::Tuple::AnyPortAnyInterfaceCompare::operator()(), operator<(), operator==(), setPort(), and Tuple().
Data resip::Tuple::mTargetDomain [private] |
Definition at line 262 of file Tuple.hxx.
Referenced by getTargetDomain(), and setTargetDomain().
TransportType resip::Tuple::mTransportType [private] |
Definition at line 261 of file Tuple.hxx.
Referenced by getType(), hash(), resip::Tuple::AnyInterfaceCompare::operator()(), resip::Tuple::AnyPortCompare::operator()(), resip::Tuple::AnyPortAnyInterfaceCompare::operator()(), operator<(), operator==(), and setType().
Definition at line 182 of file Tuple.hxx.
Referenced by resip::ConnectionManager::findConnection(), main(), makeTupleFromBinaryToken(), resip::TcpBaseTransport::processAllWriteRequests(), resip::SipStack::sendOverExistingConnection(), resip::TransportSelector::transmit(), and writeBinaryToken().
| char resip::Tuple::pad[28] |
Definition at line 181 of file Tuple.hxx.
Referenced by resip::ConnectionBase::ConnectionBase(), resip::TransactionState::handleSync(), resip::UdpTransport::processRxParse(), and resip::TransportSelector::transmit().
| TransportKey resip::Tuple::transportKey |
Definition at line 178 of file Tuple.hxx.
Referenced by resip::ConnectionBase::ConnectionBase(), resip::TransportSelector::findTransportByDest(), makeTupleFromBinaryToken(), resip::UdpTransport::processRxParse(), resip::TransportSelector::retransmit(), resip::TransportSelector::transmit(), and writeBinaryToken().
1.7.5.1