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"
54 class RTPIPv4Destination
57 RTPIPv4Destination(uint32_t ip,uint16_t rtpportbase)
59 memset(&rtpaddr,0,
sizeof(
struct sockaddr_in));
60 memset(&rtcpaddr,0,
sizeof(
struct sockaddr_in));
62 rtpaddr.sin_family = AF_INET;
63 rtpaddr.sin_port = htons(rtpportbase);
64 rtpaddr.sin_addr.s_addr = htonl(ip);
66 rtcpaddr.sin_family = AF_INET;
67 rtcpaddr.sin_port = htons(rtpportbase+1);
68 rtcpaddr.sin_addr.s_addr = htonl(ip);
70 RTPIPv4Destination::ip = ip;
73 bool operator==(
const RTPIPv4Destination &src)
const
75 if (rtpaddr.sin_addr.s_addr == src.rtpaddr.sin_addr.s_addr && rtpaddr.sin_port == src.rtpaddr.sin_port)
79 uint32_t GetIP()
const {
return ip; }
81 uint32_t GetIP_NBO()
const {
return rtpaddr.sin_addr.s_addr; }
82 uint16_t GetRTPPort_NBO()
const {
return rtpaddr.sin_port; }
83 uint16_t GetRTCPPort_NBO()
const {
return rtcpaddr.sin_port; }
84 const struct sockaddr_in *GetRTPSockAddr()
const {
return &rtpaddr; }
85 const struct sockaddr_in *GetRTCPSockAddr()
const {
return &rtcpaddr; }
87 std::string GetDestinationString()
const;
91 struct sockaddr_in rtpaddr;
92 struct sockaddr_in rtcpaddr;
96 inline std::string RTPIPv4Destination::GetDestinationString()
const
99 uint32_t ip = ipaddr_hbo;
100 uint16_t portbase = ntohs(rtpport_nbo);
102 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));
103 return std::string(str);
107 #endif // RTPIPV4DESTINATION_H