version 1.1.2.1, 2007/06/08 10:43:20
|
version 1.1.2.2, 2007/06/12 09:31:58
|
|
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <string.h> |
|
#include <stdlib.h> |
|
#include <ctype.h> |
|
#include <Pegasus/Common/String.h> |
|
#include <Pegasus/Common/HostAddress.h> | #include <Pegasus/Common/HostAddress.h> |
#include <Pegasus/Common/PegasusAssert.h> |
|
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
#if defined (PEGASUS_OS_TYPE_WINDOWS) || defined (PEGASUS_DISABLE_IPV6) |
#ifdef PEGASUS_OS_VMS |
|
const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; |
|
#endif |
|
|
|
#if defined (PEGASUS_OS_TYPE_WINDOWS) || !defined (PEGASUS_ENABLE_IPV6) |
| |
/* | /* |
Address conversion utility functions. | Address conversion utility functions. |
|
|
return 1; | return 1; |
} | } |
| |
#ifndef PEGASUS_DISABLE_IPV6 |
#ifdef PEGASUS_ENABLE_IPV6 |
/* | /* |
Converts given ipv6 text address (ex. ::1) to binary form and stroes | Converts given ipv6 text address (ex. ::1) to binary form and stroes |
in "dst" buffer (ex. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1). Returns 1 | in "dst" buffer (ex. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1). Returns 1 |
|
|
return dst; | return dst; |
} | } |
| |
#ifndef PEGASUS_DISABLE_IPV6 |
#ifdef PEGASUS_ENABLE_IPV6 |
/* | /* |
Converts given ipv6 address in binary form to text form. Ex. | Converts given ipv6 address in binary form to text form. Ex. |
0000000000000001 to ::1. | 0000000000000001 to ::1. |
|
|
return dst; | return dst; |
} | } |
#endif | #endif |
#endif // defined (PEGASUS_OS_TYPE_WINDOWS) || defined (PEGASUS_DISABLE_IPV6) |
#endif // defined (PEGASUS_OS_TYPE_WINDOWS) || !defined (PEGASUS_ENABLE_IPV6) |
| |
void HostAddress::_init() | void HostAddress::_init() |
{ | { |
|
|
{ | { |
switch (af) | switch (af) |
{ | { |
#ifndef PEGASUS_DISABLE_IPV6 |
#ifdef PEGASUS_ENABLE_IPV6 |
case AF_INET6: | case AF_INET6: |
return !memcmp(p1, p2, sizeof(struct in6_addr)); | return !memcmp(p1, p2, sizeof(struct in6_addr)); |
#endif | #endif |
|
|
_isValid = false; | _isValid = false; |
return; | return; |
} | } |
|
|
Uint32 i = 0; | Uint32 i = 0; |
#ifndef PEGASUS_DISABLE_IPV6 |
#ifdef PEGASUS_ENABLE_IPV6 |
if (_hostAddrStr[0] == '[') | if (_hostAddrStr[0] == '[') |
{ | { |
i = 1; | i = 1; |
|
|
return; | return; |
} | } |
} | } |
|
else if ((_isValid = isValidIPV6Address(_hostAddrStr))) |
|
{ |
|
_addrType = AT_IPV6; |
|
_hostAddress = _hostAddrStr; |
|
return; |
|
} |
else | else |
#endif | #endif |
if (!_isValid) | if (!_isValid) |
|
|
} | } |
} | } |
| |
#ifndef PEGASUS_DISABLE_IPV6 |
#ifdef PEGASUS_ENABLE_IPV6 |
Boolean HostAddress::isValidIPV6Address (const String &ipv6Address) | Boolean HostAddress::isValidIPV6Address (const String &ipv6Address) |
{ | { |
CString addr = ipv6Address.getCString(); | CString addr = ipv6Address.getCString(); |
|
|
| |
int HostAddress::convertTextToBinary(int af, const char *src, void *dst) | int HostAddress::convertTextToBinary(int af, const char *src, void *dst) |
{ | { |
#ifdef PEGASUS_DISABLE_IPV6 |
#ifndef PEGASUS_ENABLE_IPV6 |
if (af == AF_INET) | if (af == AF_INET) |
{ | { |
return _inet_ptonv4(src, dst); | return _inet_ptonv4(src, dst); |
} | } |
return -1; | return -1; |
#else | #else |
#ifdef PEGASUS_OS_TYPE_UNIX |
#if defined (PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS) |
return ::inet_pton(af, src, dst); | return ::inet_pton(af, src, dst); |
#else | #else |
if (af == AF_INET) | if (af == AF_INET) |
|
|
return -1; // Unsupported address family. | return -1; // Unsupported address family. |
} | } |
#endif // PEGASUS_OS_TYPE_UNIX | #endif // PEGASUS_OS_TYPE_UNIX |
#endif // PEGASUS_DISABLE_IPV6 |
#endif // PEGASUS_ENABLE_IPV6 |
} | } |
| |
const char * HostAddress::convertBinaryToText(int af, const void *src, | const char * HostAddress::convertBinaryToText(int af, const void *src, |
char *dst, Uint32 size) | char *dst, Uint32 size) |
{ | { |
#ifdef PEGASUS_DISABLE_IPV6 |
#ifndef PEGASUS_ENABLE_IPV6 |
if (af == AF_INET) | if (af == AF_INET) |
{ | { |
return _inet_ntopv4(src, dst, size); | return _inet_ntopv4(src, dst, size); |
} | } |
return 0; | return 0; |
#else | #else |
#ifdef PEGASUS_OS_TYPE_UNIX |
#if defined (PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS) |
return ::inet_ntop(af, src, dst, size); | return ::inet_ntop(af, src, dst, size); |
#else | #else |
if (af == AF_INET) | if (af == AF_INET) |
|
|
return 0; // Unsupported address family. | return 0; // Unsupported address family. |
} | } |
#endif // PEGASUS_OS_TYPE_UNIX | #endif // PEGASUS_OS_TYPE_UNIX |
#endif // PEGASUS_DISABLE_IPV6 |
#endif // PEGASUS_ENABLE_IPV6 |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |