![]() |
VR-Link API Documentation for HLA 1516
|
00001 /********************************************************************* 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 *********************************************************************/ 00009 #pragma once 00010 00011 #include <vlutil/vlInet.h> 00012 #include <vlutil/vlString.h> 00013 00014 #ifdef DtUSE_UTILITIES_NAMESPACE 00015 namespace DtUSE_UTILITIES_NAMESPACE 00016 { 00017 #endif 00018 00019 class DtInetAddr; 00020 00023 namespace DtInetUtils 00024 { 00028 #define DtUSE_DEFAULT_INET_ADDR 0 00029 #define DtINET_IGMPv4_MGMT_GROUP_ADDR 0xE0000001 // == 224.0.0.1 00030 00031 #define DtInet_IPv4_ADDR_LEN sizeof( struct in_addr ) 00032 #define DtInet_IPv6_ADDR_LEN sizeof( struct in6_addr ) 00033 00037 #define DtNetResLocType_NONE 0 00038 #define DtNetResLocType_PORT 1 00039 #define DtNetResLocType_NETMASK 2 00040 #define DtNetResLocType_PREFIXLEN 3 00041 00042 00044 #define DtINET_IPv4_LINK_LOCAL_MASK 0xa9fe0000 // == 169.254.0.0/16 00045 #define DtINET_IPv4_LOOPBACK_MASK 0x7f000001 // == 127.0.0.1 00046 #define DtINET_IPv6_LINK_LOCAL_MASK 0xfe80 // uppermost 10 bits of address 00047 00049 00052 // NB: The reason these values are not the same as AF_INET and AF_INET6 is 00053 // simply to make it easier to use these enums in log messages that 00054 // identify an address family. 00055 enum DtInetAddrFamily 00056 { 00057 DtInetAddrFamily_INVALID = 0, 00058 DtInetAddrFamily_IPv4 = 4, 00059 DtInetAddrFamily_IPv6 = 6, 00060 DtInetAddrFamily_Both = 99 00061 }; 00062 00064 00073 DT_DLL_VLUTIL DtInetAddrFamily addrStringFamily(const DtString& addrString); 00074 00080 DT_DLL_VLUTIL bool isIpv4AddrString(const DtString& addrString); 00081 00087 DT_DLL_VLUTIL bool isIpv6AddrString(const DtString& addrString); 00088 00093 DT_DLL_VLUTIL bool isLoopbackAddrString(const DtString& addrString); 00094 00099 DT_DLL_VLUTIL bool isLocalhostAddrString(const DtString& addrString); 00100 00105 DT_DLL_VLUTIL bool isLinkLocalAddrString(const DtString& addrString); 00106 00112 DT_DLL_VLUTIL bool isMulticastAddrString(const DtString& addrString); 00113 00118 DT_DLL_VLUTIL bool isBroadcastAddrString(const DtString& addrString); 00119 00140 DT_DLL_VLUTIL DtInetAddrFamily parseNetResLoc(const DtString& nrl, DtString& parsedNrl, 00141 DtString& modifier, int& modifierType); 00142 00149 DT_DLL_VLUTIL bool parseIpv4NetResLoc(const DtString& nrl, DtString& parsedNrl, 00150 DtString& modifier, int& modifierType); 00151 DT_DLL_VLUTIL bool parseIpv6NetResLoc(const DtString& nrl, DtString& parsedNrl, 00152 DtString& modifier, int& modifierType); 00153 00155 DT_DLL_VLUTIL DtU32 prefixLenToIpv4Netmask( DtU32 prefixLen ); 00156 00158 DT_DLL_VLUTIL DtU32 netmaskToPrefixLen( DtU32 netmask ); 00159 00164 DT_DLL_VLUTIL DtU32 convertStringToNetmask( DtString maskString ); 00165 00169 DT_DLL_VLUTIL DtU32 convertStringToPrefixLen( DtString maskString ); 00170 00176 DT_DLL_VLUTIL DtInetAddr* getPrimaryBroadcastAddress(bool preferIpv6 = false); 00177 00180 DT_DLL_VLUTIL const char* removeZoneIndex(char* addrStr); 00181 00183 00184 #ifdef _WIN32 00185 inline bool IN6_IS_ADDR_BROADCAST(const struct in6_addr *a) 00186 { 00187 return ( IN6_IS_ADDR_MC_LINKLOCAL(a) 00188 && ((a->s6_bytes[2] & 0xf) == 0) && ((a->s6_bytes[3] & 0xf) == 0) 00189 && ((a->s6_bytes[4] & 0xf) == 0) && ((a->s6_bytes[5] & 0xf) == 0) 00190 && ((a->s6_bytes[6] & 0xf) == 0) && ((a->s6_bytes[7] & 0xf) == 0) 00191 && ((a->s6_bytes[8] & 0xf) == 0) && ((a->s6_bytes[9] & 0xf) == 0) 00192 && ((a->s6_bytes[10] & 0xf) == 0) && ((a->s6_bytes[11] & 0xf) == 0) 00193 && ((a->s6_bytes[12] & 0xf) == 0) && ((a->s6_bytes[13] & 0xf) == 0) 00194 && ((a->s6_bytes[14] & 0xf) == 0) && ((a->s6_bytes[15] & 0xf) == 1) ); 00195 } 00196 #else // !_WIN32 00197 inline bool IN6_IS_ADDR_BROADCAST(const struct in6_addr *a) 00198 { 00199 return ( IN6_IS_ADDR_MC_LINKLOCAL(a) 00200 && ((a->s6_addr[2] & 0xf) == 0) && ((a->s6_addr[3] & 0xf) == 0) 00201 && ((a->s6_addr[4] & 0xf) == 0) && ((a->s6_addr[5] & 0xf) == 0) 00202 && ((a->s6_addr[6] & 0xf) == 0) && ((a->s6_addr[7] & 0xf) == 0) 00203 && ((a->s6_addr[8] & 0xf) == 0) && ((a->s6_addr[9] & 0xf) == 0) 00204 && ((a->s6_addr[10] & 0xf) == 0) && ((a->s6_addr[11] & 0xf) == 0) 00205 && ((a->s6_addr[12] & 0xf) == 0) && ((a->s6_addr[13] & 0xf) == 0) 00206 && ((a->s6_addr[14] & 0xf) == 0) && ((a->s6_addr[15] & 0xf) == 1) ); 00207 } 00208 #endif 00209 00210 } 00211 00212 #ifdef DtUSE_UTILITIES_NAMESPACE 00213 } 00214 #endif 00215 00216