reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
StunTuple.cxx
Go to the documentation of this file.
1#include "StunTuple.hxx"
2#include "rutil/Logger.hxx"
3#include "ReTurnSubsystem.hxx"
4
5using namespace std;
6
7#define RESIPROCATE_SUBSYSTEM ReTurnSubsystem::RETURN
8
9namespace reTurn {
10
11// Default constructor
13 mTransport(None),
14 mPort(0)
15{
16}
17
18StunTuple::StunTuple(TransportType transport, const asio::ip::address& address, unsigned int port) :
19 mTransport(transport),
20 mAddress(address),
21 mPort(port)
22{
23}
24
25bool
27{
28 return mTransport == rhs.mTransport &&
29 mAddress == rhs.mAddress &&
30 mPort == rhs.mPort;
31}
32
33bool
35{
36 return mTransport != rhs.mTransport ||
37 mAddress != rhs.mAddress ||
38 mPort != rhs.mPort;
39}
40
41bool
42StunTuple::operator<(const StunTuple& rhs) const
43{
44 if (mTransport < rhs.mTransport)
45 {
46 return true;
47 }
48 if (mTransport > rhs.mTransport)
49 {
50 return false;
51 }
52 if(mAddress < rhs.mAddress)
53 {
54 return true;
55 }
56 if(mAddress == rhs.mAddress)
57 {
58 return mPort < rhs.mPort;
59 }
60 return false;
61}
62
63void
64StunTuple::toSockaddr(sockaddr* addr) const
65{
66 resip_assert(!mAddress.is_unspecified());
67 if(mAddress.is_v4())
68 {
69 memset(addr, 0, sizeof(sockaddr_in));
70 sockaddr_in* sa = reinterpret_cast<sockaddr_in*>(addr);
71 sa->sin_family = AF_INET;
72 sa->sin_port = htons(mPort);
73 asio::ip::address_v4::bytes_type buf = mAddress.to_v4().to_bytes();
74 memcpy(&sa->sin_addr.s_addr, buf.data(), buf.size());
75 }
76#ifdef USE_IPV6
77 else if(mAddress.is_v6())
78 {
79 memset(addr, 0, sizeof(sockaddr_in6));
80 sockaddr_in6* sa6 = reinterpret_cast<sockaddr_in6*>(addr);
81 sa6->sin6_family = AF_INET6;
82 sa6->sin6_port = htons(mPort);
83 asio::ip::address_v6::bytes_type buf = mAddress.to_v6().to_bytes();
84 memcpy(&sa6->sin6_addr.s6_addr, buf.data(), buf.size());
85 }
86#endif
87 else
88 {
89 ErrLog(<<"mAddress is not a supported address family");
90 resip_assert(1); // FIXME
91 }
92}
93
95operator<<(EncodeStream& strm, const StunTuple& tuple)
96{
97 switch(tuple.mTransport)
98 {
99 case StunTuple::None:
100 strm << "[None ";
101 break;
102 case StunTuple::UDP:
103 strm << "[UDP ";
104 break;
105 case StunTuple::TCP:
106 strm << "[TCP ";
107 break;
108 case StunTuple::TLS:
109 strm << "[TLS ";
110 break;
111 }
112 strm << tuple.mAddress.to_string() << ":" << tuple.mPort << "]";
113 return strm;
114}
115
116} // namespace
117
118
119/* ====================================================================
120
121 Copyright (c) 2007-2008, Plantronics, Inc.
122 All rights reserved.
123
124 Redistribution and use in source and binary forms, with or without
125 modification, are permitted provided that the following conditions are
126 met:
127
128 1. Redistributions of source code must retain the above copyright
129 notice, this list of conditions and the following disclaimer.
130
131 2. Redistributions in binary form must reproduce the above copyright
132 notice, this list of conditions and the following disclaimer in the
133 documentation and/or other materials provided with the distribution.
134
135 3. Neither the name of Plantronics nor the names of its contributors
136 may be used to endorse or promote products derived from this
137 software without specific prior written permission.
138
139 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
140 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
141 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
142 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
143 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
144 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
145 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
146 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
147 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
149 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150
151 ==================================================================== */
#define ErrLog(args_)
Definition Logger.hxx:137
#define resip_assert(x)
This file needs to work for both C and C++ code.
void toSockaddr(sockaddr *addr) const
Definition StunTuple.cxx:64
bool operator==(const StunTuple &rhs) const
Definition StunTuple.cxx:26
bool operator!=(const StunTuple &rhs) const
Definition StunTuple.cxx:34
bool operator<(const StunTuple &rhs) const
Definition StunTuple.cxx:42
EncodeStream & operator<<(EncodeStream &strm, const UInt128 &r)
#define EncodeStream