![]() |
VR-Link API Documentation for DIS
|
00001 /********************************************************************* 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 *********************************************************************/ 00008 #pragma once 00009 00010 #include <vlutil/vlInet.h> 00011 #include <vlutil/vlInetAddrUtils.h> 00012 #include <vlutil/vlString.h> 00013 #include <vlutil/vlUtilTypes.h> 00014 00015 00016 #ifdef DtUSE_UTILITIES_NAMESPACE 00017 namespace DtUSE_UTILITIES_NAMESPACE 00018 { 00019 #endif 00020 00021 // Ref. RFC3513 00023 enum DtInetIpv6Scope 00024 { 00025 DtInetIpv6_Unspecified, 00026 DtInetIpv6_Interface = 1, // AKA node-local 00027 DtInetIpv6_LinkLocal = 2, 00028 DtInetIpv6_Subnet = 3, // MS only, not in RFC3513 00029 DtInetIpv6_AdminLocal = 4, // in RFC3513, but not used in Linux 00030 DtInetIpv6_SiteLocal = 5, 00031 DtInetIpv6_OrgLocal = 8, 00032 DtInetIpv6_Global = 14 00033 }; 00034 00037 class DT_DLL_VLUTIL DtInetAddr 00038 { 00039 public: 00040 00043 DtInetAddr( DtInetUtils::DtInetAddrFamily family = DtInetUtils::DtInetAddrFamily_IPv4 ); 00044 00051 DtInetAddr( const DtString& addrString, const DtString& netmaskString = "" ); 00052 DtInetAddr( const char* addrString, const char* netmaskString = NULL ); 00054 00059 DtInetAddr( const struct sockaddr_in& addr, DtU32 netmask = 0 ); 00060 DtInetAddr( const DtU32 addr, DtU32 netmask = 0 ); 00062 00064 DtInetAddr( const struct sockaddr_in6& addr, DtU32 prefixLen = 0 ); 00065 00068 DtInetAddr( const struct sockaddr_storage& addr, DtU32 prefixLen = 0 ); 00069 00073 DtInetAddr( const DtU128& addr, DtInetUtils::DtInetAddrFamily family, 00074 DtU32 prefixLen = 0); 00075 00078 DtInetAddr( void* boostAsioIpAddress ); 00079 00081 virtual ~DtInetAddr( ); 00082 00084 DtInetAddr( const DtInetAddr& orig ); 00085 00087 DtInetAddr& operator=(const DtInetAddr& orig); 00088 00092 virtual DtString toDtString( bool useShortForm = false ) const; 00093 00095 virtual DtInetUtils::DtInetAddrFamily family() const; 00096 00099 virtual bool isIPv4() const; 00100 virtual bool isIPv6() const; 00102 00105 virtual void setNetmask( DtU32 mask ); 00106 00110 virtual DtU32 netmask() const; 00111 00113 virtual void setPrefixLen( DtU64 prefixLen ); 00114 00116 virtual DtU64 prefix() const; 00117 00119 virtual bool isMulticast() const; 00120 00122 virtual bool isBroadcast() const; 00123 00125 virtual bool isLoopback() const; 00126 00129 virtual bool isAnyAddr() const; 00130 00133 virtual const DtInetAddr* getBroadcastAddr(); 00134 00136 virtual const DtInetAddr* getLoopbackAddr(); 00137 00141 virtual int toSockaddr( struct sockaddr_in* s ) const; 00142 virtual int toSockaddr( struct sockaddr_in6* s ) const; 00144 00146 virtual void toAddrStorage( struct sockaddr_storage* addrStor ) const; 00147 00149 virtual DtU128 toU128() const; 00150 00153 virtual DtU32 toULong() const; 00154 00156 virtual void setScope( DtInetIpv6Scope scopeId ); 00157 00160 virtual DtInetIpv6Scope scope() const; 00161 00165 virtual void* boostAddress(); 00166 virtual const void* boostAddress() const; 00167 00170 friend DT_DLL_VLUTIL bool operator==( const DtInetAddr& addr1, const DtInetAddr& addr2 ); 00171 friend DT_DLL_VLUTIL bool operator!=( const DtInetAddr& addr1, const DtInetAddr& addr2 ); 00172 friend DT_DLL_VLUTIL bool operator<( const DtInetAddr& addr1, const DtInetAddr& addr2 ); 00173 friend DT_DLL_VLUTIL bool operator>( const DtInetAddr& addr1, const DtInetAddr& addr2 ); 00175 00176 static const DtInetAddr& inaddrAny(DtInetUtils::DtInetAddrFamily family = DtInetUtils::DtInetAddrFamily_IPv4); 00177 static const DtInetAddr& loopbackAddress(DtInetUtils::DtInetAddrFamily family = DtInetUtils::DtInetAddrFamily_IPv4); 00178 00179 protected: 00180 void init(); 00181 void initFromStrings(const char* addrString, const char* netmaskString); 00182 00183 protected: 00185 void* myAddr; 00186 00187 DtU64 myIpv4Netmask; 00188 DtU64 myPrefixLen; 00189 00190 DtInetAddr* myBroadcastAddr; 00191 DtInetAddr* myLoopbackAddr; 00192 00193 bool myIsBroadcast; 00194 bool myIsMulticast; 00195 bool myIsLoopback; 00196 bool myIsAnyAddr; 00197 00198 DtInetIpv6Scope myIpv6ScopeId; 00199 00200 }; 00201 // end of class DtInetAddr 00202 00203 #ifdef DtUSE_UTILITIES_NAMESPACE 00204 } 00205 #endif 00206