37 #ifndef RTPIPV4DESTINATION_H
39 #define RTPIPV4DESTINATION_H
41 #include "rtpconfig.h"
42 #if ! (defined(WIN32) || defined(_WIN32_WCE))
43 #include <netinet/in.h>
44 #include <arpa/inet.h>
45 #include <sys/socket.h>
48 #include "rtpdefines.h"
57 class RTPIPv4Destination
60 RTPIPv4Destination(uint32_t ip,uint16_t rtpportbase)
62 memset(&rtpaddr,0,
sizeof(
struct sockaddr_in));
63 memset(&rtcpaddr,0,
sizeof(
struct sockaddr_in));
65 rtpaddr.sin_family = AF_INET;
66 rtpaddr.sin_port = htons(rtpportbase);
67 rtpaddr.sin_addr.s_addr = htonl(ip);
69 rtcpaddr.sin_family = AF_INET;
70 rtcpaddr.sin_port = htons(rtpportbase+1);
71 rtcpaddr.sin_addr.s_addr = htonl(ip);
73 RTPIPv4Destination::ip = ip;
76 bool operator==(
const RTPIPv4Destination &src)
const
78 if (rtpaddr.sin_addr.s_addr == src.rtpaddr.sin_addr.s_addr && rtpaddr.sin_port == src.rtpaddr.sin_port)
82 uint32_t GetIP()
const {
return ip; }
84 uint32_t GetIP_NBO()
const {
return rtpaddr.sin_addr.s_addr; }
85 uint16_t GetRTPPort_NBO()
const {
return rtpaddr.sin_port; }
86 uint16_t GetRTCPPort_NBO()
const {
return rtcpaddr.sin_port; }
87 const struct sockaddr_in *GetRTPSockAddr()
const {
return &rtpaddr; }
88 const struct sockaddr_in *GetRTCPSockAddr()
const {
return &rtcpaddr; }
90 std::string GetDestinationString()
const;
94 struct sockaddr_in rtpaddr;
95 struct sockaddr_in rtcpaddr;
99 inline std::string RTPIPv4Destination::GetDestinationString()
const
102 uint32_t ip = GetIP();
103 uint16_t portbase = ntohs(GetRTPPort_NBO());
105 RTP_SNPRINTF(str,24,
"%d.%d.%d.%d:%d",(
int)((ip>>24)&0xFF),(
int)((ip>>16)&0xFF),(
int)((ip>>8)&0xFF),(
int)(ip&0xFF),(
int)(portbase));
106 return std::string(str);
112 #endif // RTPIPV4DESTINATION_H