summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjha <jha@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-06-13 02:45:40 +0000
committerjha <jha@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2001-06-13 02:45:40 +0000
commit6c1b77da3d96b22f9afdf9303e896d45197e2fd5 (patch)
treee8399cc11a82b69cfb9a31baa59becce7cab6cd7
parent15d0cd6cb4a2b9225477b080ffb826de443872a5 (diff)
downloadATCD-6c1b77da3d96b22f9afdf9303e896d45197e2fd5.tar.gz
Merged the changes from the previous IPv6 branch and modified
INET_Addr.{cpp,h,i} to be much more maintainable. This is a very workable version. No tests yet.
-rw-r--r--ace/INET_Addr.cpp281
-rw-r--r--ace/INET_Addr.h60
-rw-r--r--ace/INET_Addr.i53
-rw-r--r--ace/OS.i10
-rw-r--r--ace/README2
-rw-r--r--ace/SOCK_Acceptor.cpp215
-rw-r--r--ace/SOCK_Connector.cpp12
7 files changed, 445 insertions, 188 deletions
diff --git a/ace/INET_Addr.cpp b/ace/INET_Addr.cpp
index 93f27515a29..e4527b5aa76 100644
--- a/ace/INET_Addr.cpp
+++ b/ace/INET_Addr.cpp
@@ -74,19 +74,17 @@ ACE_INET_Addr::operator == (const ACE_INET_Addr &sap) const
{
ACE_TRACE ("ACE_INET_Addr::operator ==");
- return this->inet_addr_.sin_port == sap.inet_addr_.sin_port
- && ACE_OS::memcmp ((void *) &this->inet_addr_.sin_addr,
- (void *) &sap.inet_addr_.sin_addr,
- sizeof (this->inet_addr_.sin_addr)) == 0;
+ return this->get_port_number() == sap.get_port_number()
+ && ACE_OS::memcmp (this->addr_pointer(),
+ sap.addr_pointer(),
+ this->addr_size()) == 0;
}
ACE_INET_Addr::ACE_INET_Addr (void)
- : ACE_Addr (AF_INET, sizeof this->inet_addr_)
+ : ACE_Addr (ACE_ADDRESS_FAMILY, sizeof this->inet_addr_)
{
// ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
- (void) ACE_OS::memset ((void *) &this->inet_addr_,
- 0,
- sizeof this->inet_addr_);
+ this->initialize();
}
int
@@ -99,9 +97,7 @@ ACE_INET_Addr::set (const ACE_INET_Addr &sa)
if (sa.get_type () == AF_ANY)
// Ugh, this is really a base class, so don't copy it.
- (void) ACE_OS::memset ((void *) &this->inet_addr_,
- 0,
- sizeof this->inet_addr_);
+ this->initialize();
else
// It's ok to make the copy.
(void) ACE_OS::memcpy ((void *) &this->inet_addr_,
@@ -165,7 +161,7 @@ ACE_INET_Addr::set (const char address[])
}
ACE_INET_Addr::ACE_INET_Addr (const char address[])
- : ACE_Addr (AF_INET, sizeof this->inet_addr_)
+ : ACE_Addr (ACE_ADDRESS_FAMILY, sizeof this->inet_addr_)
{
ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
this->set (address);
@@ -173,7 +169,7 @@ ACE_INET_Addr::ACE_INET_Addr (const char address[])
#if defined (ACE_HAS_WCHAR)
ACE_INET_Addr::ACE_INET_Addr (const wchar_t address[])
- : ACE_Addr (AF_INET, sizeof this->inet_addr_)
+ : ACE_Addr (ACE_ADDRESS_FAMILY, sizeof this->inet_addr_)
{
ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
this->set (address);
@@ -184,7 +180,7 @@ ACE_INET_Addr::ACE_INET_Addr (const wchar_t address[])
// Copy constructor.
ACE_INET_Addr::ACE_INET_Addr (const ACE_INET_Addr &sa)
- : ACE_Addr (AF_INET, sizeof this->inet_addr_)
+ : ACE_Addr (ACE_ADDRESS_FAMILY, sizeof this->inet_addr_)
{
ACE_TRACE ("ACE_INET_Addr::ACE_INET_Addr");
this->set (sa);
@@ -199,28 +195,17 @@ ACE_INET_Addr::set (u_short port_number,
int encode)
{
ACE_TRACE ("ACE_INET_Addr::set");
- this->ACE_Addr::base_set (AF_INET, sizeof this->inet_addr_);
- (void) ACE_OS::memset ((void *) &this->inet_addr_,
- 0, sizeof this->inet_addr_);
- this->inet_addr_.sin_family = AF_INET;
-#if defined (ACE_HAS_SIN_LEN)
- this->inet_addr_.sin_len = sizeof this->inet_addr_;
-#endif /* ACE_HAS_SIN_LEN */
+ this->set_address((char*)&inet_address,
+ sizeof inet_address,
+ encode);
- if (encode)
- {
- inet_address = htonl (inet_address);
- this->inet_addr_.sin_port = htons (port_number);
- }
- else
- this->inet_addr_.sin_port = port_number;
+ this->set_port_number(port_number,
+ encode);
- (void) ACE_OS::memcpy ((void *) &this->inet_addr_.sin_addr,
- (void *) &inet_address,
- sizeof this->inet_addr_.sin_addr);
return 0;
}
+
// Initializes a ACE_INET_Addr from a PORT_NUMBER and the remote
// HOST_NAME.
@@ -230,11 +215,13 @@ ACE_INET_Addr::set (u_short port_number,
int encode)
{
ACE_TRACE ("ACE_INET_Addr::set");
- ACE_UINT32 addr;
+ ACE_UINT32 addrv4;
+#if defined (ACE_HAS_IPV6)
+ in6_addr addrv6;
+#endif
- this->ACE_Addr::base_set (AF_INET, sizeof this->inet_addr_);
- (void) ACE_OS::memset ((void *) &this->inet_addr_, 0, sizeof
- this->inet_addr_);
+ this->ACE_Addr::base_set (ACE_ADDRESS_FAMILY, sizeof this->inet_addr_);
+ this->initialize();
// Yow, someone gave us a NULL host_name!
if (host_name == 0)
@@ -242,11 +229,32 @@ ACE_INET_Addr::set (u_short port_number,
errno = EINVAL;
return -1;
}
+#if defined (ACE_HAS_IPV6)
+ else if (ACE_OS::inet_pton (AF_INET6,
+ host_name,
+ (void*)&addrv6) == 1) {
+ this->set_address((char*)&addrv6,
+ sizeof addrv6,
+ 0);
+ this->set_port_number(port_number,
+ encode);
+
+ return 0;
+ }
+ else if (ACE_OS::inet_pton (AF_INET,
+ host_name,
+ (void*)&addrv4) == 1)
+ {
+ return this->set (port_number,
+ addrv4,0);
+ }
+#else
else if (ACE_OS::inet_aton (host_name,
- (struct in_addr *) &addr) == 1)
+ (struct in_addr *) &addrv4) == 1)
return this->set (port_number,
- encode ? ntohl (addr) : addr,
+ encode ? ntohl (addrv4) : addrv4,
encode);
+#endif /* ACE_HAS_IPV6 */
else
{
#if defined (VXWORKS) || defined (CHORUS)
@@ -267,11 +275,11 @@ ACE_INET_Addr::set (u_short port_number,
}
else
{
- (void) ACE_OS::memcpy ((void *) &addr,
+ (void) ACE_OS::memcpy ((void *) &addrv4,
hp->h_addr,
hp->h_length);
return this->set (port_number,
- encode ? ntohl (addr) : addr,
+ encode ? ntohl (addrv4) : addrv4,
encode);
}
}
@@ -390,9 +398,14 @@ int
ACE_INET_Addr::set (const sockaddr_in *addr, int len)
{
ACE_TRACE ("ACE_INET_Addr::set");
- this->ACE_Addr::base_set (AF_INET, len);
- ACE_OS::memcpy ((void *) &this->inet_addr_,
- (void *) addr, len);
+ this->ACE_Addr::base_set (ACE_ADDRESS_FAMILY, len);
+
+ this->set_address((char*)&addr->sin_addr,
+ sizeof addr->sin_addr,
+ 0);
+ this->set_port_number(addr->sin_port,
+ 0);
+
return 0;
}
@@ -402,7 +415,7 @@ ACE_INET_Addr::set_addr (void *addr, int len)
{
ACE_TRACE ("ACE_INET_Addr::set_addr");
- this->ACE_Addr::base_set (AF_INET, len);
+ this->ACE_Addr::base_set (ACE_ADDRESS_FAMILY, len);
ACE_OS::memcpy ((void *) &this->inet_addr_,
(void *) addr, len);
}
@@ -426,7 +439,7 @@ ACE_INET_Addr::ACE_INET_Addr (u_short port_number,
if (this->set (port_number, inet_address) == -1)
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT ("%p\n"),
- ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
+ ACE_LIB_TEXT ("ACE_INET_Addr::ACE_INET_Addr")));
}
// Creates a ACE_INET_Addr from a PORT_NAME and the remote
@@ -492,6 +505,15 @@ ACE_INET_Addr::get_host_name (char hostname[],
size_t len) const
{
ACE_TRACE ("ACE_INET_Addr::get_host_name");
+#if defined (ACE_HAS_IPV6)
+ ACE_UNUSED_ARG (hostname);
+ ACE_UNUSED_ARG (len);
+
+ // XXXXXXXXXXXXX
+ printf("get_host_name is not defined for IPv6 yet\n");
+ return 0;
+
+#else
if (this->inet_addr_.sin_addr.s_addr == INADDR_ANY)
{
@@ -504,7 +526,7 @@ ACE_INET_Addr::get_host_name (char hostname[],
{
#if defined (VXWORKS)
ACE_UNUSED_ARG (len);
- int error =
+ int error =
::hostGetByAddr ((int) this->inet_addr_.sin_addr.s_addr,
hostname);
if (error == OK)
@@ -532,7 +554,7 @@ ACE_INET_Addr::get_host_name (char hostname[],
#else
hostent hentry;
ACE_HOSTENT_DATA buf;
- hostent *hp =
+ hostent *hp =
ACE_OS::gethostbyaddr_r ((char *)&this->inet_addr_.sin_addr,
a_len,
this->addr_type_,
@@ -560,6 +582,8 @@ ACE_INET_Addr::get_host_name (char hostname[],
return 0;
#endif /* VXWORKS */
}
+
+#endif /* ACE_HAS_IPV6 */
}
#if defined (ACE_HAS_WCHAR)
@@ -580,7 +604,7 @@ ACE_INET_Addr::get_host_name (wchar_t hostname[],
// And copy it over, if successful
if (result == 0)
- ACE_OS_String::strcpy (hostname,
+ ACE_OS_String::strcpy (hostname,
ACE_Ascii_To_Wide (char_hostname).wchar_rep ());
return result;
@@ -609,5 +633,168 @@ ACE_INET_Addr::set_port_number (u_short port_number,
if (encode)
port_number = htons (port_number);
+#if defined (ACE_HAS_IPV6)
+ this->inet_addr_.sin6_port = port_number;
+#else
this->inet_addr_.sin_port = port_number;
+#endif
+}
+
+int ACE_INET_Addr::set_address (const char *ip_addr,
+ int len,
+ int encode /* = 1 */)
+{
+ ACE_TRACE ("ACE_INET_Addr::set");
+
+ this->ACE_Addr::base_set (ACE_ADDRESS_FAMILY, sizeof this->inet_addr_);
+#if defined (ACE_HAS_IPV6)
+ this->inet_addr_.sin6_family = ACE_ADDRESS_FAMILY;
+#else
+ this->inet_addr_.sin_family = ACE_ADDRESS_FAMILY;
+#endif
+
+ if(len == 4)
+ {
+ ACE_UINT32 ip4 = *ACE_reinterpret_cast (const ACE_UINT32 *, ip_addr);
+ if(encode) {
+ ip4 = htonl(ip4);
+ }
+#if defined (ACE_HAS_IPV6)
+ if(ip4 == INADDR_ANY) {
+ in6_addr ip6 = in6addr_any;
+ memcpy(this->addr_pointer(),(void*)&ip6,this->addr_size());
+ return 0;
+ }
+
+ /* Build up a 128 bit address. An IPv4-mapped IPv6 address is
+ defined as 0:0:0:0:0:ffff:IPv4_address. This id defined in RFC 1884 */
+ struct {
+ ACE_UINT16 prefix[5];
+ ACE_UINT16 ffff;
+ ACE_UINT32 addr;
+ } newaddress = {
+ { 0,0,0,0,0 },
+ 0xffff,
+ ip4
+ };
+
+ memcpy(this->addr_pointer(),(void*)&newaddress,this->addr_size());
+#else /* ACE_HAS_IPV6 */
+ memcpy(this->addr_pointer(),(void*)&ip4,this->addr_size());
+#endif
+
+ return 0;
+ }
+#if defined (ACE_HAS_IPV6)
+ else
+ {
+ if(encode)
+ printf("It doesn't make sense to encode for IPv6 addresses.\n");
+ memcpy(this->addr_pointer(),(void*)ip_addr,this->addr_size());
+ return 0;
+ }
+#endif /* ACE_HAS_IPV6 */
+
+ return -1;
+}
+const char *
+ACE_INET_Addr::get_host_addr (char *dst, int size) const
+{
+#if defined (ACE_HAS_IPV6)
+ if(IN6_IS_ADDR_V4MAPPED(&this->inet_addr_.sin6_addr)) {
+ ACE_UINT32 addr;
+ addr = this->get_ip_address();
+ return ACE_OS::inet_ntop (AF_INET, (const void*)&addr,dst,size);
+ }
+ dst[0] = '[';
+ const char *ch = ACE_OS::inet_ntop (AF_INET6, (const void*)&this->inet_addr_.sin6_addr,dst+1,size-1);
+ if(ch == 0) {
+ dst[0] = '\0';
+ return 0;
+ }
+ int end = ACE_OS::strlen(dst);
+ dst[end] = ']';
+ dst[end+1] = '\0';
+ return dst;
+
+#elif defined (VXWORKS)
+ // It would be nice to be able to encapsulate this into
+ // ACE_OS::inet_ntoa(), but that would lead to either inefficiencies
+ // on vxworks or lack of thread safety.
+ //
+ // So, we use the way that vxworks suggests.
+ ACE_INET_Addr *ncthis = ACE_const_cast (ACE_INET_Addr *, this);
+ inet_ntoa_b (this->inet_addr_.sin_addr, ncthis->buf_);
+ return &buf_[0];
+#else /* VXWORKS */
+ return ACE_OS::inet_ntoa (this->inet_addr_.sin_addr);
+#endif
+}
+
+// Return the dotted Internet address.
+const char *
+ACE_INET_Addr::get_host_addr (void) const
+{
+ ACE_TRACE ("ACE_INET_Addr::get_host_addr");
+#if defined (ACE_HAS_IPV6)
+ static char buf[INET6_ADDRSTRLEN];
+ return this->get_host_addr(buf,INET6_ADDRSTRLEN);
+#else
+ return ACE_OS::inet_ntoa (this->inet_addr_.sin_addr);
+#endif
+}
+
+// Return the 4-byte IP address, converting it into host byte order.
+
+ACE_UINT32
+ACE_INET_Addr::get_ip_address (void) const
+{
+ ACE_TRACE ("ACE_INET_Addr::get_ip_address");
+#if defined (ACE_HAS_IPV6)
+ if(IN6_IS_ADDR_V4MAPPED(&this->inet_addr_.sin6_addr)) {
+ ACE_UINT32 addr;
+ // Return the last 32 bits of the address
+ char *thisaddrptr = (char*)this->addr_pointer();
+ thisaddrptr += 128/8 - 32/8;
+ memcpy((void*)&addr,(void*)(thisaddrptr),sizeof(addr));
+ return ntohl(addr);
+ } else {
+ ACE_ERROR ((LM_ERROR,
+ ACE_LIB_TEXT ("ACE_INET_Addr::get_ip_address: address is a IPv6 address not IPv4\n")));
+ return 0;
+ }
+#else
+ return ntohl (ACE_UINT32 (this->inet_addr_.sin_addr.s_addr));
+#endif
+}
+
+// For now keep this in INET_Addr.cpp for easy compiling. Move them
+// into INET_Addr.i for inlining later.
+void *ACE_INET_Addr::addr_pointer(void) const
+{
+#if defined (ACE_HAS_IPV6)
+ return (void*)&this->inet_addr_.sin6_addr;
+#else
+ return (void*)&this->inet_addr_.sin_addr;
+#endif
+}
+
+size_t ACE_INET_Addr::addr_size(void) const
+{
+#if defined (ACE_HAS_IPV6)
+ return sizeof this->inet_addr_.sin6_addr;
+#else
+ return sizeof this->inet_addr_.sin_addr;
+#endif
+}
+
+void ACE_INET_Addr::initialize(void)
+{
+ (void) ACE_OS::memset ((void *) &this->inet_addr_,
+ 0, sizeof this->inet_addr_);
+#if defined (ACE_HAS_IPV6)
+ this->inet_addr_.sin6_family = ACE_ADDRESS_FAMILY;
+#else
+ this->inet_addr_.sin_family = ACE_ADDRESS_FAMILY;
+#endif
}
diff --git a/ace/INET_Addr.h b/ace/INET_Addr.h
index 25f3ad1049c..25847d3a5aa 100644
--- a/ace/INET_Addr.h
+++ b/ace/INET_Addr.h
@@ -27,6 +27,14 @@
# include /**/ "inetLib.h"
#endif /* VXWORKS */
+// I don't know if this is a good place to put this, but it's
+// the most logical.
+#if defined (ACE_HAS_IPV6)
+#define ACE_ADDRESS_FAMILY AF_INET6
+#else
+#define ACE_ADDRESS_FAMILY AF_INET
+#endif
+
/**
* @class ACE_INET_Addr
*
@@ -66,12 +74,12 @@ public:
* are in host byte order.
*/
ACE_INET_Addr (u_short port_number,
- ACE_UINT32 ip_addr = INADDR_ANY);
+ ACE_UINT32 ip_addr = INADDR_ANY);
/// Uses <getservbyname> to create an <ACE_INET_Addr> from a
/// <port_name>, the remote <host_name>, and the <protocol>.
ACE_INET_Addr (const char port_name[],
- const char host_name[],
+ const char host_name[],
const char protocol[] = "tcp");
/**
@@ -80,7 +88,7 @@ public:
* method assumes that <ip_addr> is in host byte order.
*/
ACE_INET_Addr (const char port_name[],
- ACE_UINT32 ip_addr,
+ ACE_UINT32 ip_addr,
const char protocol[] = "tcp");
#if defined (ACE_HAS_WCHAR)
@@ -90,11 +98,11 @@ public:
ACE_EXPLICIT ACE_INET_Addr (const wchar_t address[]);
ACE_INET_Addr (const wchar_t port_name[],
- const wchar_t host_name[],
+ const wchar_t host_name[],
const wchar_t protocol[] = ACE_TEXT_WIDE ("tcp"));
ACE_INET_Addr (const wchar_t port_name[],
- ACE_UINT32 ip_addr,
+ ACE_UINT32 ip_addr,
const wchar_t protocol[] = ACE_TEXT_WIDE ("tcp"));
#endif /* ACE_HAS_WCHAR */
@@ -115,7 +123,7 @@ public:
* in network byte order already and are passed straight through.
*/
int set (u_short port_number,
- const char host_name[],
+ const char host_name[],
int encode = 1);
/**
@@ -132,7 +140,7 @@ public:
/// Uses <getservbyname> to initialize an <ACE_INET_Addr> from a
/// <port_name>, the remote <host_name>, and the <protocol>.
int set (const char port_name[],
- const char host_name[],
+ const char host_name[],
const char protocol[] = "tcp");
/**
@@ -141,7 +149,7 @@ public:
* <ip_addr> is already in network byte order.
*/
int set (const char port_name[],
- ACE_UINT32 ip_addr,
+ ACE_UINT32 ip_addr,
const char protocol[] = "tcp");
/**
@@ -155,19 +163,19 @@ public:
/// Creates an <ACE_INET_Addr> from a sockaddr_in structure.
int set (const sockaddr_in *,
- int len);
+ int len);
#if defined (ACE_HAS_WCHAR)
int set (u_short port_number,
- const wchar_t host_name[],
+ const wchar_t host_name[],
int encode = 1);
int set (const wchar_t port_name[],
- const wchar_t host_name[],
+ const wchar_t host_name[],
const wchar_t protocol[] = ACE_TEXT_WIDE ("tcp"));
int set (const wchar_t port_name[],
- ACE_UINT32 ip_addr,
+ ACE_UINT32 ip_addr,
const wchar_t protocol[] = ACE_TEXT_WIDE ("tcp"));
int set (const wchar_t addr[]);
@@ -216,7 +224,18 @@ public:
* already and are passed straight through.
*/
void set_port_number (u_short,
- int encode = 1);
+ int encode = 1);
+
+ /**
+ * Sets the address without affecting the port number. If
+ * <encode> is enabled then <ip_addr> is converted into network
+ * byte order, otherwise it is assumed to be in network byte order
+ * already and are passed straight through. The size of the address
+ * is specified in the <len> parameter.
+ */
+ int set_address (const char *ip_addr,
+ int len,
+ int encode = 1);
/// Return the port number, converting it into host byte order.
u_short get_port_number (void) const;
@@ -243,6 +262,7 @@ public:
/// Return the "dotted decimal" Internet address.
const char *get_host_addr (void) const;
+ const char *get_host_addr (char *dst, int size) const;
/// Return the 4-byte IP address, converting it into host byte
/// order.
@@ -273,8 +293,22 @@ public:
ACE_ALLOC_HOOK_DECLARE;
private:
+ // Methods to gain access to the actual address of
+ // the underlying internet address structure.
+ void *addr_pointer(void) const;
+ size_t addr_size(void) const;
+
+ // Initialize the underlying internet address structure.
+ // This sets the structure to zeros and sets the address
+ // family.
+ void initialize(void);
+
/// Underlying representation.
+#if defined (ACE_HAS_IPV6)
+ sockaddr_in6 inet_addr_;
+#else
sockaddr_in inet_addr_;
+#endif
#if defined (VXWORKS)
char buf_[INET_ADDR_LEN];
diff --git a/ace/INET_Addr.i b/ace/INET_Addr.i
index 2ec940e02c4..5e419feafbb 100644
--- a/ace/INET_Addr.i
+++ b/ace/INET_Addr.i
@@ -15,7 +15,11 @@ ACE_INLINE u_short
ACE_INET_Addr::get_port_number (void) const
{
ACE_TRACE ("ACE_INET_Addr::get_port_number");
+#if defined (ACE_HAS_IPV6)
+ return ntohs (this->inet_addr_.sin6_port);
+#else
return ntohs (this->inet_addr_.sin_port);
+#endif
}
// Return the address.
@@ -27,36 +31,7 @@ ACE_INET_Addr::get_addr (void) const
return (void *) &this->inet_addr_;
}
-// Return the dotted Internet address.
-
-ACE_INLINE const char *
-ACE_INET_Addr::get_host_addr (void) const
-{
- ACE_TRACE ("ACE_INET_Addr::get_host_addr");
-#if defined (VXWORKS)
- // It would be nice to be able to encapsulate this into
- // ACE_OS::inet_ntoa(), but that would lead to either inefficiencies
- // on vxworks or lack of thread safety.
- //
- // So, we use the way that vxworks suggests.
- ACE_INET_Addr *ncthis = ACE_const_cast (ACE_INET_Addr *, this);
- inet_ntoa_b (this->inet_addr_.sin_addr, ncthis->buf_);
- return &buf_[0];
-#else /* VXWORKS */
- return ACE_OS::inet_ntoa (this->inet_addr_.sin_addr);
-#endif /* VXWORKS */
-}
-
-// Return the 4-byte IP address, converting it into host byte order.
-
-ACE_INLINE ACE_UINT32
-ACE_INET_Addr::get_ip_address (void) const
-{
- ACE_TRACE ("ACE_INET_Addr::get_ip_address");
- return ntohl (ACE_UINT32 (this->inet_addr_.sin_addr.s_addr));
-}
-
-ACE_INLINE u_long
+ACE_INLINE u_long
ACE_INET_Addr::hash (void) const
{
return this->get_ip_address () + this->get_port_number ();
@@ -71,27 +46,27 @@ ACE_INET_Addr::operator < (const ACE_INET_Addr &rhs) const
}
#if defined (ACE_HAS_WCHAR)
-ACE_INLINE int
-ACE_INET_Addr::set (u_short port_number,
- const wchar_t host_name[],
+ACE_INLINE int
+ACE_INET_Addr::set (u_short port_number,
+ const wchar_t host_name[],
int encode)
{
- return this->set (port_number,
+ return this->set (port_number,
ACE_Wide_To_Ascii (host_name).char_rep (),
encode);
}
-ACE_INLINE int
+ACE_INLINE int
ACE_INET_Addr::set (const wchar_t port_name[],
- const wchar_t host_name[],
+ const wchar_t host_name[],
const wchar_t protocol[])
{
- return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
+ return this->set (ACE_Wide_To_Ascii (port_name).char_rep (),
ACE_Wide_To_Ascii (host_name).char_rep (),
ACE_Wide_To_Ascii (protocol).char_rep ());
}
-ACE_INLINE int
+ACE_INLINE int
ACE_INET_Addr::set (const wchar_t port_name[],
ACE_UINT32 ip_addr,
const wchar_t protocol[])
@@ -101,7 +76,7 @@ ACE_INET_Addr::set (const wchar_t port_name[],
ACE_Wide_To_Ascii (protocol).char_rep ());
}
-ACE_INLINE int
+ACE_INLINE int
ACE_INET_Addr::set (const wchar_t addr[])
{
return this->set (ACE_Wide_To_Ascii (addr).char_rep ());
diff --git a/ace/OS.i b/ace/OS.i
index 37d24b4f833..acbfb88e3d7 100644
--- a/ace/OS.i
+++ b/ace/OS.i
@@ -5889,7 +5889,7 @@ ACE_OS::gethostbyname2 (const char *name, int family)
ACE_UNUSED_ARG (name);
ACE_UNUSED_ARG (family);
ACE_NOTSUP_RETURN (0);
-# elif defined (ACE_HAS_IP6)
+# elif defined (ACE_HAS_IPV6)
# if defined (ACE_HAS_NONCONST_GETBY)
ACE_SOCKCALL_RETURN (::gethostbyname2 (ACE_const_cast (char *, name),
family),
@@ -7198,7 +7198,7 @@ ACE_OS::inet_pton (int family, const char *strptr, void *addrptr)
{
ACE_OS_TRACE ("ACE_OS::inet_pton");
-#if defined (ACE_HAS_IP6)
+#if defined (ACE_HAS_IPV6)
ACE_OSCALL_RETURN (::inet_pton (family, strptr, addrptr), int, -1);
#else
if (family == AF_INET)
@@ -7215,7 +7215,7 @@ ACE_OS::inet_pton (int family, const char *strptr, void *addrptr)
}
ACE_NOTSUP_RETURN(-1);
-#endif /* ACE_HAS_IP6 */
+#endif /* ACE_HAS_IPV6 */
}
ACE_INLINE const char *
@@ -7223,7 +7223,7 @@ ACE_OS::inet_ntop (int family, const void *addrptr, char *strptr, size_t len)
{
ACE_OS_TRACE ("ACE_OS::inet_ntop");
-#if defined (ACE_HAS_IP6)
+#if defined (ACE_HAS_IPV6)
ACE_OSCALL_RETURN (::inet_ntop (family, addrptr, strptr, len), const char *, 0);
#else
const u_char *p =
@@ -7251,7 +7251,7 @@ ACE_OS::inet_ntop (int family, const void *addrptr, char *strptr, size_t len)
}
ACE_NOTSUP_RETURN(0);
-#endif /* ACE_HAS_IP6 */
+#endif /* ACE_HAS_IPV6 */
}
ACE_INLINE int
diff --git a/ace/README b/ace/README
index 84c9045ff74..327a1bc2f9c 100644
--- a/ace/README
+++ b/ace/README
@@ -331,7 +331,7 @@ ACE_HAS_INLINED_OSCALLS Inline all the static class OS
methods to remove call
overhead
ACE_HAS_IP_MULTICAST Platform supports IP multicast
-ACE_HAS_IP6 Platform supports IPv6.
+ACE_HAS_IPV6 Platform supports IPv6.
ACE_HAS_IRIX62_THREADS Platform supports the very odd
IRIX 6.2 threads...
ACE_HAS_NONSTATIC_OBJECT_MANAGER Causes the ACE_Object_Manager
diff --git a/ace/SOCK_Acceptor.cpp b/ace/SOCK_Acceptor.cpp
index 8477e4809ca..5d0d59ee97c 100644
--- a/ace/SOCK_Acceptor.cpp
+++ b/ace/SOCK_Acceptor.cpp
@@ -25,8 +25,8 @@ ACE_SOCK_Acceptor::ACE_SOCK_Acceptor (void)
int
ACE_SOCK_Acceptor::shared_accept_start (ACE_Time_Value *timeout,
- int restart,
- int &in_blocking_mode) const
+ int restart,
+ int &in_blocking_mode) const
{
ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_start");
@@ -36,20 +36,20 @@ ACE_SOCK_Acceptor::shared_accept_start (ACE_Time_Value *timeout,
if (timeout != 0)
{
if (ACE::handle_timed_accept (handle,
- timeout,
- restart) == -1)
- return -1;
+ timeout,
+ restart) == -1)
+ return -1;
else
- {
- in_blocking_mode = ACE_BIT_DISABLED (ACE::get_flags (handle),
- ACE_NONBLOCK);
- // Set the handle into non-blocking mode if it's not already
- // in it.
- if (in_blocking_mode
- && ACE::set_flags (handle,
- ACE_NONBLOCK) == -1)
- return -1;
- }
+ {
+ in_blocking_mode = ACE_BIT_DISABLED (ACE::get_flags (handle),
+ ACE_NONBLOCK);
+ // Set the handle into non-blocking mode if it's not already
+ // in it.
+ if (in_blocking_mode
+ && ACE::set_flags (handle,
+ ACE_NONBLOCK) == -1)
+ return -1;
+ }
}
return 0;
@@ -57,8 +57,8 @@ ACE_SOCK_Acceptor::shared_accept_start (ACE_Time_Value *timeout,
int
ACE_SOCK_Acceptor::shared_accept_finish (ACE_SOCK_Stream new_stream,
- int in_blocking_mode,
- int reset_new_handle) const
+ int in_blocking_mode,
+ int reset_new_handle) const
{
ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_finish ()");
@@ -75,9 +75,9 @@ ACE_SOCK_Acceptor::shared_accept_finish (ACE_SOCK_Stream new_stream,
// Only disable ACE_NONBLOCK if we weren't in non-blocking mode
// originally.
ACE::clr_flags (this->get_handle (),
- ACE_NONBLOCK);
+ ACE_NONBLOCK);
ACE::clr_flags (new_handle,
- ACE_NONBLOCK);
+ ACE_NONBLOCK);
}
#if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
@@ -96,7 +96,7 @@ ACE_SOCK_Acceptor::shared_accept_finish (ACE_SOCK_Stream new_stream,
int
ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
ACE_Addr *remote_addr,
- ACE_Time_Value *timeout,
+ ACE_Time_Value *timeout,
int restart,
int reset_new_handle) const
{
@@ -104,8 +104,8 @@ ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
int in_blocking_mode = 0;
if (this->shared_accept_start (timeout,
- restart,
- in_blocking_mode) == -1)
+ restart,
+ in_blocking_mode) == -1)
return -1;
else
{
@@ -116,38 +116,38 @@ ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
int len = 0;
if (remote_addr != 0)
- {
- len = remote_addr->get_size ();
+ {
+ len = remote_addr->get_size ();
len_ptr = &len;
- addr = (sockaddr *) remote_addr->get_addr ();
- }
+ addr = (sockaddr *) remote_addr->get_addr ();
+ }
do
- new_stream.set_handle (ACE_OS::accept (this->get_handle (),
- addr,
- len_ptr));
+ new_stream.set_handle (ACE_OS::accept (this->get_handle (),
+ addr,
+ len_ptr));
while (new_stream.get_handle () == ACE_INVALID_HANDLE
- && restart != 0
- && errno == EINTR
- && timeout == 0);
+ && restart != 0
+ && errno == EINTR
+ && timeout == 0);
// Reset the size of the addr, which is only necessary for UNIX
// domain sockets.
if (new_stream.get_handle () != ACE_INVALID_HANDLE
- && remote_addr != 0)
- remote_addr->set_size (len);
+ && remote_addr != 0)
+ remote_addr->set_size (len);
}
return this->shared_accept_finish (new_stream,
- in_blocking_mode,
- reset_new_handle);
+ in_blocking_mode,
+ reset_new_handle);
}
int
ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
- ACE_Accept_QoS_Params qos_params,
+ ACE_Accept_QoS_Params qos_params,
ACE_Addr *remote_addr,
- ACE_Time_Value *timeout,
+ ACE_Time_Value *timeout,
int restart,
int reset_new_handle) const
{
@@ -155,8 +155,8 @@ ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
int in_blocking_mode = 0;
if (this->shared_accept_start (timeout,
- restart,
- in_blocking_mode) == -1)
+ restart,
+ in_blocking_mode) == -1)
return -1;
else
{
@@ -167,32 +167,32 @@ ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
sockaddr *addr = 0;
if (remote_addr != 0)
- {
- len = remote_addr->get_size ();
+ {
+ len = remote_addr->get_size ();
len_ptr = &len;
- addr = (sockaddr *) remote_addr->get_addr ();
- }
+ addr = (sockaddr *) remote_addr->get_addr ();
+ }
do
- new_stream.set_handle (ACE_OS::accept (this->get_handle (),
- addr,
- len_ptr,
- qos_params));
+ new_stream.set_handle (ACE_OS::accept (this->get_handle (),
+ addr,
+ len_ptr,
+ qos_params));
while (new_stream.get_handle () == ACE_INVALID_HANDLE
- && restart != 0
- && errno == EINTR
- && timeout == 0);
+ && restart != 0
+ && errno == EINTR
+ && timeout == 0);
// Reset the size of the addr, which is only necessary for UNIX
// domain sockets.
if (new_stream.get_handle () != ACE_INVALID_HANDLE
- && remote_addr != 0)
- remote_addr->set_size (len);
+ && remote_addr != 0)
+ remote_addr->set_size (len);
}
return this->shared_accept_finish (new_stream,
- in_blocking_mode,
- reset_new_handle);
+ in_blocking_mode,
+ reset_new_handle);
}
void
@@ -209,6 +209,42 @@ ACE_SOCK_Acceptor::shared_open (const ACE_Addr &local_sap,
ACE_TRACE ("ACE_SOCK_Acceptor::shared_open");
int error = 0;
+ #if defined (ACE_HAS_IPV6)
+ if (protocol_family == PF_INET6)
+ {
+ sockaddr_in6 local_inet6_addr;
+ ACE_OS::memset (ACE_reinterpret_cast (void *,
+ &local_inet6_addr),
+ 0,
+ sizeof local_inet6_addr);
+
+ if (local_sap == ACE_Addr::sap_any)
+ {
+ local_inet6_addr.sin6_family = AF_INET6;
+ local_inet6_addr.sin6_port = 0;
+ local_inet6_addr.sin6_addr = in6addr_any;
+ }
+ else
+ local_inet6_addr = *ACE_reinterpret_cast (sockaddr_in6 *,
+ local_sap.get_addr ());
+
+ if (local_inet6_addr.sin6_port == 0)
+ {
+ /* XXX Need to write bind_port for IPv6 network */
+ printf("Cannot bind to a port that is not specified for IPv6 yet\n");
+ /*
+ if (ACE::bind_port (this->get_handle (),
+ local_inet6_addr.sin6_addr.s_addr) == -1)
+ */
+ error = 1;
+ }
+ else if (ACE_OS::bind (this->get_handle (),
+ ACE_reinterpret_cast (sockaddr *,
+ &local_inet6_addr),
+ sizeof local_inet6_addr) == -1)
+ error = 1;
+ } else
+ #endif
if (protocol_family == PF_INET)
{
sockaddr_in local_inet_addr;
@@ -238,7 +274,7 @@ ACE_SOCK_Acceptor::shared_open (const ACE_Addr &local_sap,
error = 1;
}
else if (ACE_OS::bind (this->get_handle (),
- (sockaddr *) local_sap.get_addr (),
+ (sockaddr *) local_sap.get_addr (),
local_sap.get_size ()) == -1)
error = 1;
@@ -265,13 +301,21 @@ ACE_SOCK_Acceptor::open (const ACE_Addr &local_sap,
{
ACE_TRACE ("ACE_SOCK_Acceptor::open");
+ // For AF_INET6 addresses we need PF_INET6 sockets in order to
+ // properly bind to IPv6 addresses.
+#if defined (ACE_HAS_IPV6)
+ if(local_sap.get_type() == AF_INET6) {
+ protocol_family = PF_INET6;
+ }
+#endif
+
if (ACE_SOCK::open (SOCK_STREAM,
- protocol_family,
- protocol,
+ protocol_family,
+ protocol,
protocolinfo,
g,
flags,
- reuse_addr) == -1)
+ reuse_addr) == -1)
return -1;
else
return this->shared_open (local_sap,
@@ -293,30 +337,35 @@ ACE_SOCK_Acceptor::ACE_SOCK_Acceptor (const ACE_Addr &local_sap,
protocolinfo,
g,
flags,
- reuse_addr,
- protocol_family,
- backlog,
- protocol) == -1)
+ reuse_addr,
+ protocol_family,
+ backlog,
+ protocol) == -1)
ACE_ERROR ((LM_ERROR,
- ACE_LIB_TEXT ("%p\n"),
- ACE_LIB_TEXT ("ACE_SOCK_Acceptor")));
+ ACE_LIB_TEXT ("%p\n"),
+ ACE_LIB_TEXT ("ACE_SOCK_Acceptor")));
}
// General purpose routine for performing server ACE_SOCK creation.
int
ACE_SOCK_Acceptor::open (const ACE_Addr &local_sap,
- int reuse_addr,
- int protocol_family,
- int backlog,
- int protocol)
+ int reuse_addr,
+ int protocol_family,
+ int backlog,
+ int protocol)
{
ACE_TRACE ("ACE_SOCK_Acceptor::open");
+#if defined (ACE_HAS_IPV6)
+ if(local_sap.get_type() == AF_INET6)
+ protocol_family = PF_INET6;
+#endif
+
if (ACE_SOCK::open (SOCK_STREAM,
- protocol_family,
- protocol,
- reuse_addr) == -1)
+ protocol_family,
+ protocol,
+ reuse_addr) == -1)
return -1;
else
return this->shared_open (local_sap,
@@ -327,23 +376,23 @@ ACE_SOCK_Acceptor::open (const ACE_Addr &local_sap,
// General purpose routine for performing server ACE_SOCK creation.
ACE_SOCK_Acceptor::ACE_SOCK_Acceptor (const ACE_Addr &local_sap,
- int reuse_addr,
- int protocol_family,
- int backlog,
- int protocol)
+ int reuse_addr,
+ int protocol_family,
+ int backlog,
+ int protocol)
{
ACE_TRACE ("ACE_SOCK_Acceptor::ACE_SOCK_Acceptor");
if (this->open (local_sap,
- reuse_addr,
- protocol_family,
- backlog,
- protocol) == -1)
+ reuse_addr,
+ protocol_family,
+ backlog,
+ protocol) == -1)
ACE_ERROR ((LM_ERROR,
- ACE_LIB_TEXT ("%p\n"),
- ACE_LIB_TEXT ("ACE_SOCK_Acceptor")));
+ ACE_LIB_TEXT ("%p\n"),
+ ACE_LIB_TEXT ("ACE_SOCK_Acceptor")));
}
-int
+int
ACE_SOCK_Acceptor::close (void)
{
return ACE_SOCK::close ();
diff --git a/ace/SOCK_Connector.cpp b/ace/SOCK_Connector.cpp
index 062df45f423..0bb183e0dd9 100644
--- a/ace/SOCK_Connector.cpp
+++ b/ace/SOCK_Connector.cpp
@@ -148,6 +148,12 @@ ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
int protocol)
{
ACE_TRACE ("ACE_SOCK_Connector::connect");
+
+#if defined (ACE_HAS_IPV6)
+ if(remote_sap.get_type() == AF_INET6)
+ protocol_family = PF_INET6;
+#endif
+
if (this->shared_open (new_stream,
protocol_family,
protocol,
@@ -183,6 +189,12 @@ ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
int protocol)
{
ACE_TRACE ("ACE_SOCK_Connector::connect");
+
+#if defined (ACE_HAS_IPV6)
+ if(remote_sap.get_type() == AF_INET6)
+ protocol_family = PF_INET6;
+#endif
+
if (this->shared_open (new_stream,
protocol_family,
protocol,