RTP Audio System
2.0.0
|
00001 /* 00002 * $Id: internetaddress.h 1441 2012-07-03 16:38:31Z dreibh $ 00003 * 00004 * SocketAPI implementation for the sctplib. 00005 * Copyright (C) 1999-2012 by Thomas Dreibholz 00006 * 00007 * Realized in co-operation between 00008 * - Siemens AG 00009 * - University of Essen, Institute of Computer Networking Technology 00010 * - University of Applied Sciences, Muenster 00011 * 00012 * Acknowledgement 00013 * This work was partially funded by the Bundesministerium fuer Bildung und 00014 * Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045). 00015 * The authors alone are responsible for the contents. 00016 * 00017 * This program is free software: you can redistribute it and/or modify 00018 * it under the terms of the GNU General Public License as published by 00019 * the Free Software Foundation, either version 3 of the License, or 00020 * (at your option) any later version. 00021 00022 * This program is distributed in the hope that it will be useful, 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 * GNU General Public License for more details. 00026 * 00027 * You should have received a copy of the GNU General Public License 00028 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00029 * 00030 * Contact: discussion@sctp.de 00031 * dreibh@iem.uni-due.de 00032 * tuexen@fh-muenster.de 00033 * 00034 * Purpose: Internet Address Implementation 00035 * 00036 */ 00037 00038 #ifndef INTERNETADDRESS_H 00039 #define INTERNETADDRESS_H 00040 00041 00042 #include "tdsystem.h" 00043 #include "strings.h" 00044 #include "socketaddress.h" 00045 #include "portableaddress.h" 00046 00047 00048 #include <netinet/in.h> 00049 #include <resolv.h> 00050 00051 00052 00060 class InternetAddress : virtual public SocketAddress 00061 { 00062 // ====== Constructors/Destructor ======================================== 00063 public: 00067 InternetAddress(); 00068 00074 InternetAddress(const InternetAddress& address); 00075 00082 InternetAddress(const String& address); 00083 00090 InternetAddress(const String& hostName, 00091 const card16 port); 00092 00098 InternetAddress(const card16 port); 00099 00107 InternetAddress(const sockaddr* address, const socklen_t length); 00108 00112 ~InternetAddress(); 00113 00114 00115 // ====== Initialization ================================================= 00119 void reset(); 00120 00126 SocketAddress* duplicate() const; 00127 00131 void init(const InternetAddress& address); 00132 00139 void init(const String& hostName, const card16 port); 00140 00146 void init(const card16 port); 00147 00155 void init(const sockaddr* address, const socklen_t length); 00156 00157 00158 // ====== Operators ====================================================== 00162 inline InternetAddress& operator=(const InternetAddress& source); 00163 00164 00165 // ====== Address manipulation =========================================== 00171 card16 getPort() const; 00172 00178 void setPort(const card16 port); 00179 00180 00181 // ====== Address functions ============================================== 00187 bool isValid() const; 00188 00194 integer getFamily() const; 00195 00201 String getAddressString(const cardinal format = PF_Default) const; 00202 00208 inline bool isIPv4() const; 00209 00215 inline bool isIPv4compatible() const; 00216 00224 inline bool isIPv6() const; 00225 00234 inline bool isNull() const; 00235 00245 inline bool isUnspecified() const; 00246 00252 inline bool isLoopback() const; 00253 00259 inline bool isLinkLocal() const; 00260 00267 inline bool isSiteLocal() const; 00268 00274 inline bool isGlobal() const; 00275 00281 inline bool isMulticast() const; 00282 00288 inline bool isBroadcast() const; 00289 00295 inline bool isUnicast() const; 00296 00302 inline bool isReserved() const; 00303 00309 inline bool isNodeLocalMulticast() const; 00310 00316 inline bool isLinkLocalMulticast() const; 00317 00323 inline bool isSiteLocalMulticast() const; 00324 00330 inline bool isOrgLocalMulticast() const; 00331 00337 inline bool isGlobalMulticast() const; 00338 00339 00340 // ====== Get/set system sockaddr structure ============================== 00346 cardinal getSystemAddress(sockaddr* buffer, 00347 const socklen_t length, 00348 const cardinal type) const; 00349 00355 bool setSystemAddress(const sockaddr* address, const socklen_t length); 00356 00357 00358 // ====== IPv6 support functions ======================================== 00369 static cardinal getHostByName(const String& name, card16* myadr, card16* myscope = NULL); 00370 00377 static card16 getServiceByName(const char* name); 00378 00386 static bool getFullHostName(char* str, const size_t size); 00387 00393 static inline bool hasIPv6(); 00394 00402 static bool UseIPv6; 00403 00404 00405 // ====== Get local address for a connection ============================= 00418 static InternetAddress getLocalAddress(const InternetAddress& peer); 00419 00420 00421 // ====== Comparision operators ========================================= 00425 int operator==(const InternetAddress& address) const; 00426 00430 inline int operator!=(const InternetAddress& address) const; 00431 00435 int operator<(const InternetAddress& address) const; 00436 00440 inline int operator<=(const InternetAddress& address) const; 00441 00445 int operator>(const InternetAddress& address) const; 00446 00450 inline int operator>=(const InternetAddress& address) const; 00451 00452 00453 // ====== Conversion from and to PortableAddress ========================= 00459 inline PortableAddress getPortableAddress() const; 00460 00466 InternetAddress(const PortableAddress& address); 00467 00473 void init(const PortableAddress& address); 00474 00475 00476 // ====== System functions =============================================== 00484 static bool setIPv4Address(const InternetAddress& address, 00485 in_addr* ipv4Address); 00486 00493 static InternetAddress getIPv4Address(const in_addr& ipv4Address); 00494 00503 static card32 calculateChecksum(card8* buffer, 00504 const cardinal bytes, 00505 card32 sum); 00506 00514 static card32 wrapChecksum(card32 sum); 00515 00516 00517 // ====== Private data =================================================== 00518 private: 00519 static bool checkIPv6(); 00520 00521 00522 private: 00527 union { 00528 card16 Host16[8]; 00529 card32 Host32[4]; 00530 in6_addr Address; 00531 } AddrSpec; 00532 00536 card16 Port; 00537 00541 card16 ScopeID; 00542 00546 bool Valid; 00547 }; 00548 00549 00550 #include "internetaddress.icc" 00551 00552 00553 #endif