1 martin 1.3 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.4 //
|
3 martin 1.3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.4 //
|
10 martin 1.3 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.4 //
|
17 martin 1.3 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.4 //
|
20 martin 1.3 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.4 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.3 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.4 //
|
28 martin 1.3 //////////////////////////////////////////////////////////////////////////
|
29 dave.sudlik 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
|
31 kumpf 1.5
|
32 dave.sudlik 1.2 #ifndef Pegasus_HostAddress_h
33 #define Pegasus_HostAddress_h
34
35 #include <Pegasus/Common/Config.h>
36 #include <Pegasus/Common/Linkage.h>
37 #include <Pegasus/Common/String.h>
38 #include <Pegasus/Common/Socket.h>
39
40 #ifdef PEGASUS_OS_VMS
41 #include <netinet/in6.h>
42 #endif
43
44 PEGASUS_NAMESPACE_BEGIN
45
46 #ifdef INET_ADDRSTRLEN
47 #define PEGASUS_INET_ADDRSTR_LEN INET_ADDRSTRLEN
48 #else
49 #define PEGASUS_INET_ADDRSTR_LEN 16
50 #endif
51
52 #ifdef INET6_ADDRSTRLEN
53 dave.sudlik 1.2 #define PEGASUS_INET6_ADDRSTR_LEN INET6_ADDRSTRLEN
54 #else
55 #define PEGASUS_INET6_ADDRSTR_LEN 46
56 #endif
57
58 #ifdef IN6ADDR_LOOPBACK_INIT
59 #define PEGASUS_IPV6_LOOPBACK_INIT IN6ADDR_LOOPBACK_INIT
60 #else
61 #define PEGASUS_IPV6_LOOPBACK_INIT {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
62 #endif
63
64
65 #ifdef INADDR_LOOPBACK
66 #define PEGASUS_IPV4_LOOPBACK_INIT INADDR_LOOPBACK
67 #else
68 #define PEGASUS_IPV4_LOOPBACK_INIT 0x7F000001
69 #endif
70
|
71 venkat.puvvada 1.6 #define PEGASUS_IPV4_LOOPBACK_RANGE_START 0x7F000000
72 #define PEGASUS_IPV4_LOOPBACK_RANGE_END 0x7FFFFFFF
73
74
|
75 dave.sudlik 1.2 #ifdef PEGASUS_ENABLE_IPV6
76 #define PEGASUS_IN6_ADDR_SIZE (sizeof (struct in6_addr))
77 #else
78 #define PEGASUS_IN6_ADDR_SIZE 0x10
79 #endif
80
81 /**
82 This class is used to store the host address. HostAddress can be Hostname or
83 IPv4 address or IPv6 address.
84 */
85
86 class PEGASUS_COMMON_LINKAGE HostAddress
87 {
88 public:
89
90 /**
91 Address types that HostAddress can have.
92 */
93 enum
94 {
95 AT_INVALID,
96 dave.sudlik 1.2 AT_IPV4 = AF_INET,
97 #ifdef PEGASUS_ENABLE_IPV6
98 AT_IPV6 = AF_INET6,
99 #else
100 AT_IPV6 = 0x17,
101 #endif
|
102 kumpf 1.5 AT_HOSTNAME
103 };
|
104 dave.sudlik 1.2
105
106 HostAddress();
107 ~HostAddress();
108
109 /**
110 Constructor. addrStr can be HostName or IPv4Address or
111 IPv6Address (without brackets).
|
112 kumpf 1.5 */
|
113 dave.sudlik 1.2 HostAddress(const String &addrStr);
114 HostAddress(const HostAddress &rhs);
115 HostAddress& operator =(const HostAddress &rhs);
|
116 kumpf 1.5
|
117 dave.sudlik 1.2 void setHostAddress(const String &addrStr);
118
119 /**
|
120 kumpf 1.5 Returns true if the constructed HostAddress is valid.
|
121 dave.sudlik 1.2 If valid it can be HostName or IPv4Address or IPv6Address.
122 Check if HostAddress is valid by using isValid() method
123 before making any calls on HostAddress object.
124 */
125 Boolean isValid();
126
127 /**
128 Verifies given IPv4Address and returns true if it is valid.
129 */
130 static Boolean isValidIPV4Address(const String &ipv4Address);
131
132 /**
133 Verifies given IPv6Address (without brackets) and returns
134 true if it is valid.
135 */
136 static Boolean isValidIPV6Address(const String &ipv6Address);
137
138 /**
139 Verifies given hostName and returns true if it is valid.
140 */
141 static Boolean isValidHostName(const String &hostName);
142 dave.sudlik 1.2
143 /**
144 The covertBinaryToText (inet_ntop()) function shall convert a numeric
145 address into a text string suitable for presentation. The af argument
|
146 kumpf 1.5 shall specify the family of the address. This can be AF_INET or
|
147 dave.sudlik 1.2 AF_INET6. The src argument points to a buffer holding an IPv4 address
148 if the af argument is AF_INET, or an IPv6 address if the af argument is
149 AF_INET6. The address must be in network byte order. The dst argument
150 points to a buffer where the function stores the resulting text
151 string. It shall not be NULL. The size argument specifies the size of
|
152 kumpf 1.5 this buffer, which shall be large enough to hold the text string
153 (PEGASUS_INET_ADDRSTR_LEN characters for IPv4,
|
154 dave.sudlik 1.2 PEGASUS_INET6_ADDRSTR_LEN characters for IPv6).
155 */
156 static const char *convertBinaryToText(int af, const void *src,
157 char *dst, Uint32 size);
158
159 /*
160 The convertTextToBinray (inet_pton()) function shall convert an
161 address in its standard text presentation form into its numeric
162 binary form. The af argument shall specify the family
163 of the address. The AF_INET and AF_INET6 address families
164 shall be supported. The src argument points to the
165 string being passed in. The dst argument points to a buffer into which
166 the function stores the numeric address. This shall be large enough to
167 hold the numeric address (32 bits for AF_INET, 128 bits for
168 AF_INET6).
169 */
170 static int convertTextToBinary(int af, const char *src, void *dst);
171
172 /**
173 Checks whether the two addresses in binary form are equal based on
174 address family. af can be AF_INET or AF_INET6.
175 dave.sudlik 1.2 */
176 static Boolean equal(int af, void *p1, void *p2);
177
178 /**
179 Returns HostName or IPv4Address or IPv6Address. This returns an empty
180 String if HostAddress is not valid.
181 Check if HostAddress is valid by using isValid() method
182 before making any calls on HostAddress object.
183 */
184 String getHost();
185
186 /**
187 Returns address type. It can be AT_IPV4, AT_IPV6 or AT_HOSTNAME.
188 */
189 Uint32 getAddressType();
190
191 private:
192 void _init();
193 void _parseAddress();
194 String _hostAddrStr;
195 Uint16 _addrType;
196 dave.sudlik 1.2 Boolean _isValid;
197 };
198
199 PEGASUS_NAMESPACE_END
200
201 #endif //Pegasus_HostAddress_h
|