Spinning Topp Logo BlackTopp Studios
inc
networkutilities.h
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _networkutilities_h
42 #define _networkutilities_h
43 
44 #include "Network/socketdescription.h"
45 
46 struct addrinfo;
47 
48 namespace Mezzanine
49 {
50  namespace Network
51  {
52  ///////////////////////////////////////////////////////////////////////////////
53  // Byte Order Conversion
54 
55  /// @brief Converts a UInt16 from the host byte order to network byte order.
56  /// @param ToConvert The integer to be converted.
57  /// @return Returns the converted integer.
59  /// @brief Converts a UInt32 from the host byte order to network byte order.
60  /// @param ToConvert The integer to be converted.
61  /// @return Returns the converted integer.
63  /// @brief Converts a UInt16 from the network byte order to host byte order.
64  /// @param ToConvert The integer to be converted.
65  /// @return Returns the converted integer.
67  /// @brief Converts a UInt32 from the network byte order to host byte order.
68  /// @param ToConvert The integer to be converted.
69  /// @return Returns the converted integer.
71 
72  ///////////////////////////////////////////////////////////////////////////////
73  // DNS Lookup
74 
75  ///////////////////////////////////////////////////////////////////////////////
76  /// @brief A special container class used to store the results from a call to "ResolveDomainName".
77  ///////////////////////////////////////
79  {
80  protected:
81  /// @internal
82  /// @brief The count of instances that exist for these results.
84  /// @internal
85  /// @brief A pointer to the internal structure holding the resulting addresses.
86  addrinfo* Addresses;
87  /// @internal
88  /// @brief A pointer to the current address being presented.
89  addrinfo* CurrAddress;
90  /// @internal
91  /// @brief The converted values for the current address being presented.
93 
94  /// @internal
95  /// @brief Duplicates the necessary data when creating a copy instance of a set of socket results.
96  /// @param Other The other SocketResultContainer being duplicated.
97  void Aquire(const SocketResultContainer& Other);
98  /// @internal
99  /// @brief Decrements the ref count and destroys all internal data if necessary.
100  void Release();
101  public:
102  /// @brief Internal constructor.
103  /// @param Results A pointer to the internal address result structures.
104  SocketResultContainer(addrinfo* Results);
105  /// @brief Copy constructor.
106  /// @param Other The other SocketResultContainer to be constructed.
108  /// @brief Class destructor.
110 
111  ///////////////////////////////////////////////////////////////////////////////
112  // Element Access
113 
114  /// @brief Gets/converts the current result and increments the cursor to the next result if able.
115  /// @warning Do not delete the pointer returned by this method, it's pointing to a data member of this class and will cause you to have a bad time.
116  /// @return Returns a const pointer to the currently pointed to element, or NULL if the end of the container has been reached.
117  const SocketDescription* GetNextResult();
118  /// @brief Resets the current elements pointed to back to the beginning.
119  void Reset();
120  };//SocketResultContainer
121 
122  /// @brief Performs a DNS lookup with the provided domain name and port.
123  /// @param Address The numeric address of the target system.
124  /// @param Port The port on which the domain name is accepting connections.
125  /// @param TLP The transport layer protocol the target system is using to accept connections.
126  /// @return Returns a SocketResultContainer containing all matching valid socket configurations.
128  /// @brief Performs a DNS lookup with the provided domain name and service.
129  /// @remarks Examples of valid service identifiers that can be passed in here can be found at:
130  /// http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
131  /// @param DomainName The domain name to lookup, must not have a trailing slash, whitespace, or service identifier. For example "www.google.com" is valid.
132  /// @param Port The port on which the domain name is operating.
133  /// @param NLP The IP version to use when connecting to the target system.
134  /// @param TLP The transport layer protocol the target system is using to accept connections.
135  /// @return Returns a SocketResultContainer containing all matching valid socket configurations.
137  }//Network
138 }//Mezzanine
139 
140 #endif
NetworkLayerProtocol
This is an enum listing for recognized protocols on Layer 3 of the OSI model.
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Used for error conditions.
A special container class used to store the results from a call to "ResolveDomainName".
UInt16 ConvertNetworkToHostByteOrder(const UInt16 ToConvert)
Converts a UInt16 from the network byte order to host byte order.
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
TransportLayerProtocol
This is an enum listing for recognized protocols on Layer 4 of the OSI model.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
This is a simple class for representing IP addresses used throughout the Network subsystem.
Definition: ipaddress.h:57
Used for error conditions.
addrinfo * Addresses
A pointer to the internal structure holding the resulting addresses.
SocketResultContainer ResolveNumericHost(const IPAddress &Address, const UInt16 Port, const TransportLayerProtocol TLP)
Performs a DNS lookup with the provided domain name and port.
SocketDescription CurrDescription
The converted values for the current address being presented.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
A convenience class storing socket data that can be returned from utility methods and used to create ...
UInt16 ConvertHostToNetworkByteOrder(const UInt16 ToConvert)
Converts a UInt16 from the host byte order to network byte order.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Integer * RefCount
The count of instances that exist for these results.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
SocketResultContainer ResolveDomainName(const String &DomainName, const UInt16 Port, const NetworkLayerProtocol NLP, const TransportLayerProtocol TLP)
Performs a DNS lookup with the provided domain name and service.
addrinfo * CurrAddress
A pointer to the current address being presented.