JRTPLIB  3.11.0
rtpipv4address.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31 */
32 
37 #ifndef RTPIPV4ADDRESS_H
38 
39 #define RTPIPV4ADDRESS_H
40 
41 #include "rtpconfig.h"
42 #include "rtpaddress.h"
43 #include "rtptypes.h"
44 
45 namespace jrtplib
46 {
47 
48 class RTPMemoryManager;
49 
56 class JRTPLIB_IMPORTEXPORT RTPIPv4Address : public RTPAddress
57 {
58 public:
62  RTPIPv4Address(uint32_t ip = 0, uint16_t port = 0,bool rtcpmux = false):RTPAddress(IPv4Address)
63  {
64  RTPIPv4Address::ip = ip;
65  RTPIPv4Address::port = port;
66  if (rtcpmux)
67  rtcpsendport = port;
68  else
69  rtcpsendport = port+1;
70  }
71 
75  RTPIPv4Address(uint32_t ip, uint16_t port, uint16_t rtcpsendport):RTPAddress(IPv4Address)
76  {
77  RTPIPv4Address::ip = ip;
78  RTPIPv4Address::port = port;
79  RTPIPv4Address::rtcpsendport = rtcpsendport;
80  }
81 
85  RTPIPv4Address(const uint8_t ip[4],uint16_t port = 0,bool rtcpmux = false):RTPAddress(IPv4Address)
86  {
87  RTPIPv4Address::ip = (uint32_t)ip[3];
88  RTPIPv4Address::ip |= (((uint32_t)ip[2])<<8);
89  RTPIPv4Address::ip |= (((uint32_t)ip[1])<<16);
90  RTPIPv4Address::ip |= (((uint32_t)ip[0])<<24);
91 
92  RTPIPv4Address::port = port;
93  if (rtcpmux)
94  rtcpsendport = port;
95  else
96  rtcpsendport = port+1;
97  }
98 
102  RTPIPv4Address(const uint8_t ip[4],uint16_t port,uint16_t rtcpsendport):RTPAddress(IPv4Address)
103  {
104  RTPIPv4Address::ip = (uint32_t)ip[3];
105  RTPIPv4Address::ip |= (((uint32_t)ip[2])<<8);
106  RTPIPv4Address::ip |= (((uint32_t)ip[1])<<16);
107  RTPIPv4Address::ip |= (((uint32_t)ip[0])<<24);
108 
109  RTPIPv4Address::port = port;
110  RTPIPv4Address::rtcpsendport = rtcpsendport;
111  }
112 
113  ~RTPIPv4Address() { }
114 
116  void SetIP(uint32_t ip) { RTPIPv4Address::ip = ip; }
117 
119  void SetIP(const uint8_t ip[4]) { RTPIPv4Address::ip = (uint32_t)ip[3]; RTPIPv4Address::ip |= (((uint32_t)ip[2])<<8); RTPIPv4Address::ip |= (((uint32_t)ip[1])<<16); RTPIPv4Address::ip |= (((uint32_t)ip[0])<<24); }
120 
122  void SetPort(uint16_t port) { RTPIPv4Address::port = port; }
123 
125  uint32_t GetIP() const { return ip; }
126 
128  uint16_t GetPort() const { return port; }
129 
132  uint16_t GetRTCPSendPort() const { return rtcpsendport; }
133 
134  RTPAddress *CreateCopy(RTPMemoryManager *mgr) const;
135 
136  // Note that these functions are only used for received packets, and for those
137  // the rtcpsendport variable is not important and should be ignored.
138  bool IsSameAddress(const RTPAddress *addr) const;
139  bool IsFromSameHost(const RTPAddress *addr) const;
140 #ifdef RTPDEBUG
141  std::string GetAddressString() const;
142 #endif // RTPDEBUG
143 private:
144  uint32_t ip;
145  uint16_t port;
146  uint16_t rtcpsendport;
147 };
148 
149 } // end namespace
150 
151 #endif // RTPIPV4ADDRESS_H
152 
void SetIP(uint32_t ip)
Sets the IP address for this instance to ip which is assumed to be in host byte order.
Definition: rtpipv4address.h:116
uint16_t GetPort() const
Returns the port number of this instance in host byte order.
Definition: rtpipv4address.h:128
uint16_t GetRTCPSendPort() const
For outgoing packets, this indicates to which port RTCP packets will be sent (can, be the same port as the RTP packets in case RTCP multiplexing is used).
Definition: rtpipv4address.h:132
RTPIPv4Address(uint32_t ip=0, uint16_t port=0, bool rtcpmux=false)
Creates an instance with IP address ip and port number port (both are interpreted in host byte order)...
Definition: rtpipv4address.h:62
This class is an abstract class which is used to specify destinations, multicast groups etc...
Definition: rtpaddress.h:50
uint32_t GetIP() const
Returns the IP address contained in this instance in host byte order.
Definition: rtpipv4address.h:125
RTPIPv4Address(const uint8_t ip[4], uint16_t port, uint16_t rtcpsendport)
Creates an instance with IP address ip and port number port (both are interpreted in host byte order)...
Definition: rtpipv4address.h:102
Represents an IPv4 IP address and port.
Definition: rtpipv4address.h:56
Definition: rtpfaketransmitter.h:64
A memory manager.
Definition: rtpmemorymanager.h:150
RTPIPv4Address(uint32_t ip, uint16_t port, uint16_t rtcpsendport)
Creates an instance with IP address ip and port number port (both are interpreted in host byte order)...
Definition: rtpipv4address.h:75
RTPIPv4Address(const uint8_t ip[4], uint16_t port=0, bool rtcpmux=false)
Creates an instance with IP address ip and port number port (port is interpreted in host byte order) ...
Definition: rtpipv4address.h:85
void SetPort(uint16_t port)
Sets the port number for this instance to port which is interpreted in host byte order.
Definition: rtpipv4address.h:122
void SetIP(const uint8_t ip[4])
Sets the IP address of this instance to ip.
Definition: rtpipv4address.h:119