VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlInetAddrUtils.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2010 MAK Technologies, Inc
3 ** All rights reserved.
4 *********************************************************************/
9 #pragma once
10 
11 #include <vlutil/vlInet.h>
12 #include <vlutil/vlString.h>
13 
14 #ifdef DtUSE_UTILITIES_NAMESPACE
15 namespace DtUSE_UTILITIES_NAMESPACE
16 {
17 #endif
18 
19 class DtInetAddr;
20 
23 namespace DtInetUtils
24 {
28 #define DtUSE_DEFAULT_INET_ADDR 0
29 #define DtINET_IGMPv4_MGMT_GROUP_ADDR 0xE0000001 // == 224.0.0.1
30 
31 #define DtInet_IPv4_ADDR_LEN sizeof( struct in_addr )
32 #define DtInet_IPv6_ADDR_LEN sizeof( struct in6_addr )
33 
37 #define DtNetResLocType_NONE 0
38 #define DtNetResLocType_PORT 1
39 #define DtNetResLocType_NETMASK 2
40 #define DtNetResLocType_PREFIXLEN 3
41 
42 
44 #define DtINET_IPv4_LINK_LOCAL_MASK 0xa9fe0000 // == 169.254.0.0/16
45 #define DtINET_IPv4_LOOPBACK_MASK 0x7f000001 // == 127.0.0.1
46 #define DtINET_IPv6_LINK_LOCAL_MASK 0xfe80 // uppermost 10 bits of address
47 
49 
52 // NB: The reason these values are not the same as AF_INET and AF_INET6 is
53 // simply to make it easier to use these enums in log messages that
54 // identify an address family.
56 {
61 };
62 
64 
74 
80 DT_DLL_VLUTIL bool isIpv4AddrString(const DtString& addrString);
81 
87 DT_DLL_VLUTIL bool isIpv6AddrString(const DtString& addrString);
88 
93 DT_DLL_VLUTIL bool isLoopbackAddrString(const DtString& addrString);
94 
99 DT_DLL_VLUTIL bool isLocalhostAddrString(const DtString& addrString);
100 
105 DT_DLL_VLUTIL bool isLinkLocalAddrString(const DtString& addrString);
106 
112 DT_DLL_VLUTIL bool isMulticastAddrString(const DtString& addrString);
113 
118 DT_DLL_VLUTIL bool isBroadcastAddrString(const DtString& addrString, const DtString& netmaskString = "");
119 
141  DtString& modifier, int& modifierType);
142 
149 DT_DLL_VLUTIL bool parseIpv4NetResLoc(const DtString& nrl, DtString& parsedNrl,
150  DtString& modifier, int& modifierType);
151 DT_DLL_VLUTIL bool parseIpv6NetResLoc(const DtString& nrl, DtString& parsedNrl,
152  DtString& modifier, int& modifierType);
153 
156 
159 
165 
170 
176 DT_DLL_VLUTIL DtInetAddr* getPrimaryBroadcastAddress(bool preferIpv6 = false);
177 
180 DT_DLL_VLUTIL const char* removeZoneIndex(char* addrStr);
181 
183 
184 #ifdef _WIN32
185 inline bool IN6_IS_ADDR_BROADCAST(const struct in6_addr *a)
186 {
187  return ( IN6_IS_ADDR_MC_LINKLOCAL(a)
188  && ((a->s6_bytes[2] & 0xf) == 0) && ((a->s6_bytes[3] & 0xf) == 0)
189  && ((a->s6_bytes[4] & 0xf) == 0) && ((a->s6_bytes[5] & 0xf) == 0)
190  && ((a->s6_bytes[6] & 0xf) == 0) && ((a->s6_bytes[7] & 0xf) == 0)
191  && ((a->s6_bytes[8] & 0xf) == 0) && ((a->s6_bytes[9] & 0xf) == 0)
192  && ((a->s6_bytes[10] & 0xf) == 0) && ((a->s6_bytes[11] & 0xf) == 0)
193  && ((a->s6_bytes[12] & 0xf) == 0) && ((a->s6_bytes[13] & 0xf) == 0)
194  && ((a->s6_bytes[14] & 0xf) == 0) && ((a->s6_bytes[15] & 0xf) == 1) );
195 }
196 #else // !_WIN32
197 inline bool IN6_IS_ADDR_BROADCAST(const struct in6_addr *a)
198 {
199  return ( IN6_IS_ADDR_MC_LINKLOCAL(a)
200  && ((a->s6_addr[2] & 0xf) == 0) && ((a->s6_addr[3] & 0xf) == 0)
201  && ((a->s6_addr[4] & 0xf) == 0) && ((a->s6_addr[5] & 0xf) == 0)
202  && ((a->s6_addr[6] & 0xf) == 0) && ((a->s6_addr[7] & 0xf) == 0)
203  && ((a->s6_addr[8] & 0xf) == 0) && ((a->s6_addr[9] & 0xf) == 0)
204  && ((a->s6_addr[10] & 0xf) == 0) && ((a->s6_addr[11] & 0xf) == 0)
205  && ((a->s6_addr[12] & 0xf) == 0) && ((a->s6_addr[13] & 0xf) == 0)
206  && ((a->s6_addr[14] & 0xf) == 0) && ((a->s6_addr[15] & 0xf) == 1) );
207 }
208 #endif
209 
210 }
211 
212 #ifdef DtUSE_UTILITIES_NAMESPACE
213 }
214 #endif
215 
216 
bool isIpv6AddrString(const DtString &addrString)
Accepts a string representing an IPv6 address either standalone or as part of a network resource loca...
DtInetAddrFamily addrStringFamily(const DtString &addrString)
Accepts a string representing an IPv4 address (dotted decimal) either standalone or as part of a netw...
Definition: vlInetAddrUtils.h:58
bool isLoopbackAddrString(const DtString &addrString)
Accepts a string representing an IPv4 address (dotted decimal) or IPv6 address, either standalone or ...
Definition: vlInetAddrUtils.h:60
Contains the DtString class declaration.
bool IN6_IS_ADDR_BROADCAST(const struct in6_addr *a)
Definition: vlInetAddrUtils.h:197
bool isLocalhostAddrString(const DtString &addrString)
Accepts a string representing an IPv4 address (dotted decimal) or IPv6 address, either standalone or ...
bool parseIpv4NetResLoc(const DtString &nrl, DtString &parsedNrl, DtString &modifier, int &modifierType)
Accept a string representing either an IPv4 address in dotted decimal format or an IPv6 address in he...
DtU32 prefixLenToIpv4Netmask(DtU32 prefixLen)
Convert a CIDR prefix length value to an IPv4 netmask in host byte order.
Definition: vlInetAddrUtils.h:59
bool parseIpv6NetResLoc(const DtString &nrl, DtString &parsedNrl, DtString &modifier, int &modifierType)
Accepts a string representing an IPv4 address (dotted decimal) either standalone or as part of a netw...
Definition: vlInetAddrUtils.h:57
DtInetAddrFamily
Definition: vlInetAddrUtils.h:55
DtInetAddrFamily parseNetResLoc(const DtString &nrl, DtString &parsedNrl, DtString &modifier, int &modifierType)
Accept a string reference representing either a network resource locator and parses the string into t...
DtInetAddr * getPrimaryBroadcastAddress(bool preferIpv6=false)
Attempts to find the primary device capable of broadcast and returns the broadcast address of the dev...
Represents a IPv4 or IPv6 address.
Definition: vlInetAddr.h:36
const char * removeZoneIndex(char *addrStr)
Attempts to remove the zone index from the end of an IP string.
DtU32 netmaskToPrefixLen(DtU32 netmask)
Convert an IPv4 netmask in host byte order to a CIDR prefix length value.
DtU32 convertStringToPrefixLen(DtString maskString)
Accept a string reference representing either an IPv4 or IPv6 netmask prefix length (eg...
bool isMulticastAddrString(const DtString &addrString)
Accepts a string representing an IPv4 address (dotted decimal) or IPv6 address, either standalone or ...
DtU32 convertStringToNetmask(DtString maskString)
Accept a string reference representing either an IPv4 netmask in dotted decimal notation or a CIDR pr...
bool isIpv4AddrString(const DtString &addrString)
Accepts a string representing an IPv4 address (dotted decimal) either standalone or as part of a netw...
bool isBroadcastAddrString(const DtString &addrString, const DtString &netmaskString="")
Accepts a string representing an IPv4 address (dotted decimal) or IPv6 address, either standalone or ...
unsigned long DtU32
A 32 bit unsigned integer value.
Definition: vlMachineTypes.h:153
bool isLinkLocalAddrString(const DtString &addrString)
Accepts a string representing an IPv4 address (dotted decimal) or IPv6 address, either standalone or ...
Instances of DtString are used to represent strings.
Definition: vlString.h:29
This file declares useful defaults constants and static methods employed with the networking abstract...
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109

Document ID: Generated on Wed Mar 27 02:04:30 EDT 2024 from SVN revision 264570
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)