comparison deps/Platinum/ThirdParty/Neptune/Source/Core/NptNetwork.h @ 0:3425707ddbf6

Initial import (hopefully this mercurial stuff works...)
author fraserofthenight
date Mon, 06 Jul 2009 08:06:28 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3425707ddbf6
1 /*****************************************************************
2 |
3 | Neptune - Network
4 |
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 ****************************************************************/
31
32 #ifndef _NPT_NETWORK_H_
33 #define _NPT_NETWORK_H_
34
35 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "NptTypes.h"
39 #include "NptConstants.h"
40 #include "NptStrings.h"
41 #include "NptList.h"
42
43 /*----------------------------------------------------------------------
44 | constants
45 +---------------------------------------------------------------------*/
46 const unsigned int NPT_NETWORK_MAX_MAC_ADDRESS_LENGTH = 8;
47
48 /*----------------------------------------------------------------------
49 | flags
50 +---------------------------------------------------------------------*/
51 #define NPT_NETWORK_INTERFACE_FLAG_LOOPBACK 0x01
52 #define NPT_NETWORK_INTERFACE_FLAG_PROMISCUOUS 0x02
53 #define NPT_NETWORK_INTERFACE_FLAG_BROADCAST 0x04
54 #define NPT_NETWORK_INTERFACE_FLAG_MULTICAST 0x08
55 #define NPT_NETWORK_INTERFACE_FLAG_POINT_TO_POINT 0x10
56
57 /*----------------------------------------------------------------------
58 | workarounds
59 +---------------------------------------------------------------------*/
60 #if defined(_WIN32)
61 #if defined(SetPort)
62 #undef SetPort
63 #endif
64 #endif
65
66 /*----------------------------------------------------------------------
67 | types
68 +---------------------------------------------------------------------*/
69 typedef unsigned int NPT_IpPort;
70
71 /*----------------------------------------------------------------------
72 | NPT_IpAddress
73 +---------------------------------------------------------------------*/
74 class NPT_IpAddress
75 {
76 public:
77 // class members
78 static const NPT_IpAddress Any;
79
80 // constructors and destructor
81 NPT_IpAddress();
82 NPT_IpAddress(unsigned long address);
83
84 // methods
85 NPT_Result ResolveName(const char* name,
86 NPT_Timeout timeout = NPT_TIMEOUT_INFINITE);
87 NPT_Result Parse(const char* name);
88 NPT_Result Set(unsigned long address);
89 NPT_Result Set(const unsigned char bytes[4]);
90 const unsigned char* AsBytes() const;
91 unsigned long AsLong() const;
92 NPT_String ToString() const;
93
94 private:
95 // members
96 unsigned char m_Address[4];
97 };
98
99 /*----------------------------------------------------------------------
100 | NPT_MacAddress
101 +---------------------------------------------------------------------*/
102 class NPT_MacAddress
103 {
104 public:
105 // typedef enum
106 typedef enum {
107 TYPE_UNKNOWN,
108 TYPE_LOOPBACK,
109 TYPE_ETHERNET,
110 TYPE_PPP,
111 TYPE_IEEE_802_11
112 } Type;
113
114 // constructors and destructor
115 NPT_MacAddress() : m_Type(TYPE_UNKNOWN), m_Length(0) {}
116 NPT_MacAddress(Type type,
117 const unsigned char* addr,
118 unsigned int length);
119
120 // methods
121 void SetAddress(Type type, const unsigned char* addr,
122 unsigned int length);
123 Type GetType() const { return m_Type; }
124 const unsigned char* GetAddress() const { return m_Address; }
125 unsigned int GetLength() const { return m_Length; }
126 NPT_String ToString() const;
127
128 private:
129 // members
130 Type m_Type;
131 unsigned char m_Address[NPT_NETWORK_MAX_MAC_ADDRESS_LENGTH];
132 unsigned int m_Length;
133 };
134
135 /*----------------------------------------------------------------------
136 | NPT_NetworkInterfaceAddress
137 +---------------------------------------------------------------------*/
138 class NPT_NetworkInterfaceAddress
139 {
140 public:
141 // constructors and destructor
142 NPT_NetworkInterfaceAddress(const NPT_IpAddress& primary,
143 const NPT_IpAddress& broadcast,
144 const NPT_IpAddress& destination,
145 const NPT_IpAddress& netmask) :
146 m_PrimaryAddress(primary),
147 m_BroadcastAddress(broadcast),
148 m_DestinationAddress(destination),
149 m_NetMask(netmask) {}
150
151 // methods
152 const NPT_IpAddress& GetPrimaryAddress() const {
153 return m_PrimaryAddress;
154 }
155 const NPT_IpAddress& GetBroadcastAddress() const {
156 return m_BroadcastAddress;
157 }
158 const NPT_IpAddress& GetDestinationAddress() const {
159 return m_DestinationAddress;
160 }
161 const NPT_IpAddress& GetNetMask() const {
162 return m_NetMask;
163 }
164
165 private:
166 // members
167 NPT_IpAddress m_PrimaryAddress;
168 NPT_IpAddress m_BroadcastAddress;
169 NPT_IpAddress m_DestinationAddress;
170 NPT_IpAddress m_NetMask;
171 };
172
173 /*----------------------------------------------------------------------
174 | NPT_NetworkInterface
175 +---------------------------------------------------------------------*/
176 class NPT_NetworkInterface
177 {
178 public:
179 // class methods
180 static NPT_Result GetNetworkInterfaces(NPT_List<NPT_NetworkInterface*>& interfaces);
181
182 // constructors and destructor
183 NPT_NetworkInterface(const char* name,
184 const NPT_MacAddress& mac,
185 NPT_Flags flags);
186 ~NPT_NetworkInterface() {}
187
188 // methods
189 NPT_Result AddAddress(const NPT_NetworkInterfaceAddress& address);
190 const NPT_String& GetName() const {
191 return m_Name;
192 }
193 const NPT_MacAddress& GetMacAddress() const {
194 return m_MacAddress;
195 }
196 NPT_Flags GetFlags() const { return m_Flags; }
197 const NPT_List<NPT_NetworkInterfaceAddress>& GetAddresses() const {
198 return m_Addresses;
199 }
200
201 private:
202 // members
203 NPT_String m_Name;
204 NPT_MacAddress m_MacAddress;
205 NPT_Flags m_Flags;
206 NPT_List<NPT_NetworkInterfaceAddress> m_Addresses;
207 };
208
209
210 #endif // _NPT_NETWORK_H_