VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlInetDevice.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *********************************************************************/
8 #pragma once
9 
10 #include <vlutil/vlInet.h>
11 #include <vlutil/vlInetAddr.h>
12 #include <vlutil/vlString.h>
13 #include <vlutil/vlSmartPointers.h>
14 #include <vector>
15 #ifndef _WIN32
16 #include <net/if.h> // for IFNAMSIZ
17 #endif
18 
19 #ifdef DtUSE_UTILITIES_NAMESPACE
20 namespace DtUSE_UTILITIES_NAMESPACE
21 {
22 #endif
23 
24 #ifdef _WIN32
25 // Different physical network connection types have different physical address
26 // structures. Allow for more than just an Ethernet MAC address.
27 #define DtInet_MAX_PHYSADDR_LEN MAX_ADAPTER_ADDRESS_LENGTH
28 #define DtMAX_DEVICE_NAME_LEN 128 // Windows is ???? so be safe
29 #define DtInet_INITIAL_IFCONF_BUFF_SIZE sizeof(IP_ADAPTER_ADDRESSES)
30 
31 #define DtInet_IFSTATE_UP IfOperStatusUp
32 #define DtInet_IFSTATE_DOWN IfOperStatusDown
33 #define DtInet_IFSTATE_ACTIVE IfOperStatusUp
34 #define DtInet_IFSTATE_UNKNOWN IfOperStatusUnknown
35 
36 #else
37 // Different physical network connection types have different physical address
38 // structures. Allow for more than just an Ethernet MAC address.
39 #define DtInet_MAX_PHYSADDR_LEN 8
40 #define DtMAX_DEVICE_NAME_LEN IFNAMSIZ // typically 16
41 #define DtInet_INITIAL_IFCONF_BUFF_SIZE sizeof(struct ifreq)
42 #ifdef __solaris__
43 #define DtInet_INITIAL_LIFCONF_BUFF_SIZE sizeof(struct lifreq)
44 #endif
45 
46 #define DtInet_IFSTATE_UP IFF_UP
47 #define DtInet_IFSTATE_DOWN 0
48 #define DtInet_IFSTATE_ACTIVE IFF_RUNNING
49 #define DtInet_IFSTATE_UNKNOWN 0
50 
51 //#define DtInet_IF_ETHERNET ARPHRD_ETHER
52 //#define DtInet_IF_FDDI ARPHRD_FDDI
53 //#define DtInet_IF_IEEE1394 ARPHRD_IEEE1394
54 //#define DtInet_IF_WIFI ARPHRD_IEEE80211
55 //#define DtInet_IF_LOOPBACK ARPHRD_LOOPBACK
56 //#define DtInet_IF_OTHER ARPHRD_VOID
57 
58 #endif
60 
61 // The standard ifreq structure does not support IPv6 addresses (sockaddr_in6)
62 // so we have to define our own. In stark contrast to the standard ifreq struct
63 // this one stores all the information in a single structure.
64 struct ifinfo_in6
65 {
66  struct sockaddr_in6 ifinfo_addr;
67  struct sockaddr_in6 ifinfo_dstaddr;
68  struct sockaddr_in6 ifinfo_broadaddr;
69  unsigned long ifinfo_flags;
70  unsigned long ifinfo_prefix;
71  unsigned long ifinfo_scope;
72  u_short ifinfo_site6; // currently not used
73  unsigned long ifinfo_mtu; // currently not used
74 };
75 
76 struct ifreq_in6
77 {
78  char ifr6_name[DtMAX_DEVICE_NAME_LEN];
79  union
80  {
81  struct ifinfo_in6 ifru_info_in6;
82  caddr_t ifru_data;
83  } ifr6_ifru_in6;
84 #define ifr6_info_in6 ifr6_ifru_in6.ifru_info_in6
85 #define ifr6_data ifr6_ifru_in6.ifru_data
86 };
87 
89 {
96 };
97 
99 typedef DtBoost::shared_ptr<DtInetDevice> DtInetDeviceSP;
100 
102 {
103 public:
104 
108  DtInetDevice( const DtInetAddr& addr );
109  DtInetDevice( const DtString& deviceName,
111 
114 #ifdef _WIN32
115  DtInetDevice( PIP_ADAPTER_ADDRESSES devInfo,
117 #else
118 // DEBUG -- DAA what struct does SOLARIS use for IPv4 devices?
119 #ifdef __solaris__
120  DtInetDevice( int sock, struct lifreq* devInfo,
121  struct ifreq_in6* ipv6DevInfo,
123 #else
124  DtInetDevice( int sock, struct ifreq* devInfo,
125  struct ifreq_in6* ipv6DevInfo,
127 #endif
128 #endif
129 
131  DtInetDevice( const DtInetDevice& orig );
132 
134  DtInetDevice& operator=(const DtInetDevice & orig);
135 
137  virtual ~DtInetDevice();
138 
141  virtual const DtString& deviceName() const;
142 
145  virtual const DtInetAddr* addr() const;
146 
149  virtual const DtInetAddr* broadcastAddr() const;
150 
152  virtual const DtInetAddr* ipv4Addr() const;
153 
157  virtual const DtInetAddr* ipv4Netmask() const;
158 
163  virtual const DtInetAddr* ipv4BroadcastAddr() const;
164 
166  virtual const DtInetAddr* ipv6Addr() const;
167 
170  virtual const DtInetAddr* ipv6BroadcastAddr() const;
171 
174  virtual unsigned int macAddr(DtInetMacAddr& mac) const ;
175 
179  virtual const DtString& macAddrString() const;
180 
182  virtual DtInetIfLinkType type() const;
183 
185  virtual unsigned int mtu() const;
186 
188  virtual unsigned int linkState() const;
189 
192  virtual DtInetIpv6Scope linkScope() const;
193 
196  virtual bool isUp() const; // UP means enabled, not necessarily active
197  virtual bool isActive() const; // implies link is enabled (UP)
198  virtual bool isBroadcastCapable() const;
199  virtual bool isMulticastCapable() const;
200  virtual bool hasIpv4Addr() const;
201  virtual bool hasIpv6Addr() const;
203 
206  virtual unsigned int interfaceIndex() const;
207 
210  virtual bool isOk() const;
211 
213  virtual const DtString& getLastErrorString() const;
214 
216  friend DT_DLL_VLUTIL bool operator==(const DtInetDevice& dev1, const DtInetDevice& dev2);
217 // virtual bool operator==(const DtInetDevice &);
218 
219  public:
220 
222  static DtInetDevice* findInterface( const DtInetAddr& dest );
223 
224 protected:
225  void scanDeviceByName( const DtString& deviceName );
226  void initMACAddrString();
227 
228 #ifdef _WIN32
229  void init( PIP_ADAPTER_ADDRESSES devInfo );
230 #else
231 #ifdef __solaris__
232  void init( int sockFd, struct lifreq* devInfo,
233  struct ifreq_in6* ipv6DevInfo );
234 #else
235  void init( int sockFd, struct ifreq* devInfo,
236  struct ifreq_in6* ipv6DevInfo );
237 
238 #endif
239 #endif
240 
241 protected:
243 
245  unsigned int myMACAddrLen;
254 
256 
258  std::vector<DtInetAddr*> myIpv4McastAddrList;
259  std::vector<DtInetAddr*> myIpv6McastAddrList;
260 
261  unsigned int myMtu;
262  unsigned int myLinkState;
264 
265  // Interface indexes may change if the network is restarted (Linux) or an
266  // interface changes state (Windows) so it is not to be used except during
267  // initialization.
268  unsigned int myIfIndex;
269 
272 
273  // These two members are used by the *nix version of fetchDeviceInfo to
274  // cache the last values used during a successful scan of device interfaces
275  // so the next time a scan is requested it can use the buffer size as a
276  // starting point and adjust from there if necessary, rather than starting
277  // each scan from scratch.
278  unsigned int myIfconfBufferSize;
279  unsigned int myIfconfResizeFactor;
280 
281 };
282 // end of class DtInetDevice
283 
284 #ifdef DtUSE_UTILITIES_NAMESPACE
285 }
286 #endif
DtString myDeviceName
Definition: vlInetDevice.h:242
const bool operator==(const DtU128 &lhs, const DtU128 &rhs)
DtInetIpv6Scope myLinkScope
Definition: vlInetDevice.h:250
caddr_t ifru_data
Definition: vlInetDevice.h:82
Definition: vlInetAddrUtils.h:58
DtString myLastErrorString
Definition: vlInetDevice.h:271
unsigned int myLinkState
Definition: vlInetDevice.h:262
DtBoost::shared_ptr< DtInetDevice > DtInetDeviceSP
Definition: vlInetDevice.h:98
Contains the DtString class declaration.
#define DtMAX_DEVICE_NAME_LEN
Definition: vlInetDevice.h:40
unsigned long ifinfo_prefix
Definition: vlInetDevice.h:70
unsigned int myMtu
Definition: vlInetDevice.h:261
Includes Boost smart pointers and aliases the Boost namespace.
DtInetIfLinkType
Definition: vlInetDevice.h:88
DtInetAddr * myIpv6BroadcastAddr
Definition: vlInetDevice.h:253
unsigned long ifinfo_scope
Definition: vlInetDevice.h:71
Definition: vlInetDevice.h:90
DtInetAddr * myIpv6Addr
Definition: vlInetDevice.h:249
Definition: vlInetDevice.h:94
DtInetAddrFamily
Definition: vlInetAddrUtils.h:55
#define DtInet_MAX_PHYSADDR_LEN
Definition: vlInetDevice.h:39
unsigned long ifinfo_flags
Definition: vlInetDevice.h:69
Represents a IPv4 or IPv6 address.
Definition: vlInetAddr.h:36
Definition: vlInetDevice.h:92
unsigned int myMACAddrLen
Definition: vlInetDevice.h:245
DtInetIfLinkType myLinkHwType
Definition: vlInetDevice.h:263
unsigned char DtU8
An eight bit unsigned integer value.
Definition: vlMachineTypes.h:137
DtInetAddr * myIpv4Addr
Definition: vlInetDevice.h:247
Definition: vlInetDevice.h:95
This file contains the declaration of the DtInetAddr class.
DtU8 DtInetMacAddr[DtInet_MAX_PHYSADDR_LEN]
Definition: vlInetDevice.h:59
Definition: vlInetDevice.h:101
DtInetUtils::DtInetAddrFamily myDefaultAddrFam
Definition: vlInetDevice.h:255
std::vector< DtInetAddr * > myIpv4McastAddrList
Definition: vlInetDevice.h:258
unsigned int myIfIndex
Definition: vlInetDevice.h:268
bool myBroadcastEnabled
Definition: vlInetDevice.h:251
Definition: vlInetDevice.h:64
unsigned int myIfconfResizeFactor
Definition: vlInetDevice.h:279
Definition: vlInetDevice.h:93
unsigned long ifinfo_mtu
Definition: vlInetDevice.h:73
Definition: vlInetDevice.h:91
u_short ifinfo_site6
Definition: vlInetDevice.h:72
unsigned int myIfconfBufferSize
Definition: vlInetDevice.h:278
DtInetAddr * myIpv4Netmask
Definition: vlInetDevice.h:248
bool myMulticastEnabled
Definition: vlInetDevice.h:257
DtInetIpv6Scope
Definition: vlInetAddr.h:22
DtString myMACAddrString
Definition: vlInetDevice.h:246
Instances of DtString are used to represent strings.
Definition: vlString.h:29
DtInetAddr * myIpv4BroadcastAddr
Definition: vlInetDevice.h:252
Definition: vlInetDevice.h:76
std::vector< DtInetAddr * > myIpv6McastAddrList
Definition: vlInetDevice.h:259
bool myDeviceError
Definition: vlInetDevice.h:270
This file declares useful defaults constants and static methods employed with the networking abstract...
DtInetMacAddr myMACAddr
Definition: vlInetDevice.h:244
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109

Document ID: Generated on Tue Feb 2 21:02:17 EST 2021 from SVN revision 223668
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)