jrtplib 3.7.1
|
00001 /* 00002 00003 This file is a part of JRTPLIB 00004 Copyright (c) 1999-2007 Jori Liesenborgs 00005 00006 Contact: jori.liesenborgs@gmail.com 00007 00008 This library was developed at the "Expertisecentrum Digitale Media" 00009 (http://www.edm.uhasselt.be), a research center of the Hasselt University 00010 (http://www.uhasselt.be). The library is based upon work done for 00011 my thesis at the School for Knowledge Technology (Belgium/The Netherlands). 00012 00013 Permission is hereby granted, free of charge, to any person obtaining a 00014 copy of this software and associated documentation files (the "Software"), 00015 to deal in the Software without restriction, including without limitation 00016 the rights to use, copy, modify, merge, publish, distribute, sublicense, 00017 and/or sell copies of the Software, and to permit persons to whom the 00018 Software is furnished to do so, subject to the following conditions: 00019 00020 The above copyright notice and this permission notice shall be included 00021 in all copies or substantial portions of the Software. 00022 00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00024 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00026 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00028 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 00029 IN THE SOFTWARE. 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