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 RTPIPV6DESTINATION_H
00038
00039 #define RTPIPV6DESTINATION_H
00040
00041 #include "rtpconfig.h"
00042
00043 #ifdef RTP_SUPPORT_IPV6
00044
00045 #include "rtptypes.h"
00046 #include <string.h>
00047 #ifndef WIN32
00048 #include <netinet/in.h>
00049 #include <arpa/inet.h>
00050 #include <sys/socket.h>
00051 #endif // WIN32
00052 #ifdef RTPDEBUG
00053 #include "rtpdefines.h"
00054 #include <stdio.h>
00055 #include <string>
00056 #endif // RTPDEBUG
00057
00058 class RTPIPv6Destination
00059 {
00060 public:
00061 RTPIPv6Destination(in6_addr ip,uint16_t portbase)
00062 {
00063 memset(&rtpaddr,0,sizeof(struct sockaddr_in6));
00064 memset(&rtcpaddr,0,sizeof(struct sockaddr_in6));
00065 rtpaddr.sin6_family = AF_INET6;
00066 rtpaddr.sin6_port = htons(portbase);
00067 rtpaddr.sin6_addr = ip;
00068 rtcpaddr.sin6_family = AF_INET6;
00069 rtcpaddr.sin6_port = htons(portbase+1);
00070 rtcpaddr.sin6_addr = ip;
00071 }
00072 in6_addr GetIP() const { return rtpaddr.sin6_addr; }
00073 bool operator==(const RTPIPv6Destination &src) const
00074 {
00075 if (rtpaddr.sin6_port == src.rtpaddr.sin6_port && (memcmp(&(src.rtpaddr.sin6_addr),&(rtpaddr.sin6_addr),sizeof(in6_addr)) == 0))
00076 return true;
00077 return false;
00078 }
00079 const struct sockaddr_in6 *GetRTPSockAddr() const { return &rtpaddr; }
00080 const struct sockaddr_in6 *GetRTCPSockAddr() const { return &rtcpaddr; }
00081 #ifdef RTPDEBUG
00082 std::string GetDestinationString() const;
00083 #endif // RTPDEBUG
00084 private:
00085 struct sockaddr_in6 rtpaddr;
00086 struct sockaddr_in6 rtcpaddr;
00087 };
00088
00089 #ifdef RTPDEBUG
00090 inline std::string RTPIPv6Destination::GetDestinationString() const
00091 {
00092 uint16_t ip16[8];
00093 char str[48];
00094 uint16_t portbase = ntohs(rtpport_nbo);
00095 int i,j;
00096 for (i = 0,j = 0 ; j < 8 ; j++,i += 2) { ip16[j] = (((uint16_t)ip.s6_addr[i])<<8); ip16[j] |= ((uint16_t)ip.s6_addr[i+1]); }
00097 RTP_SNPRINTF(str,48,"%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X/%d",(int)ip16[0],(int)ip16[1],(int)ip16[2],(int)ip16[3],(int)ip16[4],(int)ip16[5],(int)ip16[6],(int)ip16[7],(int)portbase);
00098 return std::string(str);
00099 }
00100 #endif // RTPDEBUG
00101
00102 #endif // RTP_SUPPORT_IPV6
00103
00104 #endif // RTPIPV6DESTINATION_H
00105