00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00037 #ifndef RTPIPV4DESTINATION_H
00038
00039 #define RTPIPV4DESTINATION_H
00040
00041 #include "rtpconfig.h"
00042 #if ! (defined(WIN32) || defined(_WIN32_WCE))
00043 #include <netinet/in.h>
00044 #include <arpa/inet.h>
00045 #include <sys/socket.h>
00046 #endif // WIN32
00047 #ifdef RTPDEBUG
00048 #include "rtpdefines.h"
00049 #include <stdio.h>
00050 #include <string>
00051 #endif // RTPDEBUG
00052 #include <string.h>
00053
00054 class RTPIPv4Destination
00055 {
00056 public:
00057 RTPIPv4Destination(uint32_t ip,uint16_t rtpportbase)
00058 {
00059 memset(&rtpaddr,0,sizeof(struct sockaddr_in));
00060 memset(&rtcpaddr,0,sizeof(struct sockaddr_in));
00061
00062 rtpaddr.sin_family = AF_INET;
00063 rtpaddr.sin_port = htons(rtpportbase);
00064 rtpaddr.sin_addr.s_addr = htonl(ip);
00065
00066 rtcpaddr.sin_family = AF_INET;
00067 rtcpaddr.sin_port = htons(rtpportbase+1);
00068 rtcpaddr.sin_addr.s_addr = htonl(ip);
00069
00070 RTPIPv4Destination::ip = ip;
00071 }
00072
00073 bool operator==(const RTPIPv4Destination &src) const
00074 {
00075 if (rtpaddr.sin_addr.s_addr == src.rtpaddr.sin_addr.s_addr && rtpaddr.sin_port == src.rtpaddr.sin_port)
00076 return true;
00077 return false;
00078 }
00079 uint32_t GetIP() const { return ip; }
00080
00081 uint32_t GetIP_NBO() const { return rtpaddr.sin_addr.s_addr; }
00082 uint16_t GetRTPPort_NBO() const { return rtpaddr.sin_port; }
00083 uint16_t GetRTCPPort_NBO() const { return rtcpaddr.sin_port; }
00084 const struct sockaddr_in *GetRTPSockAddr() const { return &rtpaddr; }
00085 const struct sockaddr_in *GetRTCPSockAddr() const { return &rtcpaddr; }
00086 #ifdef RTPDEBUG
00087 std::string GetDestinationString() const;
00088 #endif // RTPDEBUG
00089 private:
00090 uint32_t ip;
00091 struct sockaddr_in rtpaddr;
00092 struct sockaddr_in rtcpaddr;
00093 };
00094
00095 #ifdef RTPDEBUG
00096 inline std::string RTPIPv4Destination::GetDestinationString() const
00097 {
00098 char str[24];
00099 uint32_t ip = ipaddr_hbo;
00100 uint16_t portbase = ntohs(rtpport_nbo);
00101
00102 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));
00103 return std::string(str);
00104 }
00105 #endif // RTPDEBUG
00106
00107 #endif // RTPIPV4DESTINATION_H
00108