rtpipv4destination.h

Go to the documentation of this file.
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 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         // nbo = network byte order
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 

Generated on Thu Feb 8 16:22:05 2007 for jrtplib by  doxygen 1.5.1