summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
Diffstat (limited to 'ace')
-rw-r--r--ace/OS_NS_macros.h5
-rw-r--r--ace/OS_NS_sys_socket.inl96
-rw-r--r--ace/README102
-rw-r--r--ace/config-linux-common.h13
4 files changed, 172 insertions, 44 deletions
diff --git a/ace/OS_NS_macros.h b/ace/OS_NS_macros.h
index 1703ce14a80..fc39d7084bf 100644
--- a/ace/OS_NS_macros.h
+++ b/ace/OS_NS_macros.h
@@ -30,8 +30,13 @@
do { TYPE ace_result_ = (TYPE) OP; \
if (ace_result_ == FAILVALUE) { int ___ = ::WSAGetLastError (); errno = ___; return (TYPE) FAILVALUE; } else return ace_result_; \
} while (0)
+# define ACE_SOCKCALL(OP,TYPE,FAILVALUE,RESULT) \
+ do { RESULT = (TYPE) OP; \
+ if (RESULT == FAILVALUE) { int ___ = ::WSAGetLastError (); errno = ___; RESULT = FAILVALUE; } \
+ } while (0)
#else
# define ACE_SOCKCALL_RETURN(OP,TYPE,FAILVALUE) ACE_OSCALL_RETURN(OP,TYPE,FAILVALUE)
+# define ACE_SOCKCALL(OP,TYPE,FAILVALUE,RESULT) ACE_OSCALL(OP,TYPE,FAILVALUE,RESULT)
#endif /* ACE_WIN32 */
#if !defined (ACE_WIN32)
diff --git a/ace/OS_NS_sys_socket.inl b/ace/OS_NS_sys_socket.inl
index 73f241bc3d9..aecd940e08e 100644
--- a/ace/OS_NS_sys_socket.inl
+++ b/ace/OS_NS_sys_socket.inl
@@ -8,6 +8,7 @@
#include "ace/OS_NS_stdio.h"
#include "ace/OS_QoS.h"
#include "ace/Global_Macros.h"
+#include "ace/os_include/netinet/os_in.h"
#if defined (ACE_HAS_VOIDPTR_SOCKOPT)
typedef void *ACE_SOCKOPT_TYPE1;
@@ -177,17 +178,59 @@ ACE_OS::getpeername (ACE_HANDLE handle, struct sockaddr *addr,
int *addrlen)
{
ACE_OS_TRACE ("ACE_OS::getpeername");
-#if defined (ACE_PSOS) && !defined ACE_PSOS_DIAB_PPC
+
+#if defined (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO) \
+ && (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO == 1)
+ int result;
+# if defined (ACE_PSOS) && !defined ACE_PSOS_DIAB_PPC
+ ACE_SOCKCALL (::getpeername ((ACE_SOCKET) handle,
+ (struct sockaddr_in *) addr,
+ (ACE_SOCKET_LEN *) addrlen),
+ int,
+ -1,
+ result);
+# else
+ ACE_SOCKCALL (::getpeername ((ACE_SOCKET) handle,
+ addr,
+ (ACE_SOCKET_LEN *) addrlen),
+ int,
+ -1,
+ result);
+# endif /* defined (ACE_PSOS) */
+
+ // Some platforms, like older versions of the Linux kernel, do not
+ // initialize the sin_zero field since that field is generally only
+ // used for padding/alignment purposes. On those platforms
+ // memcmp()-based comparisons of the sockaddr_in structure, such as
+ // the one in the ACE_INET_Addr equality operator, may fail due to
+ // random bytes in the sin_zero field even though that field is
+ // unused. Prevent equality comparison of two different sockaddr_in
+ // instances that refer to the same socket from failing by
+ // explicitly initializing the sockaddr_in::sin_zero field to a
+ // consistent value, e.g. zero.
+ if (result != -1 && addr->sa_family == AF_INET)
+ {
+ ACE_OS::memset (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero,
+ 0,
+ sizeof (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero));
+ }
+
+ return result;
+#else
+# if defined (ACE_PSOS) && !defined ACE_PSOS_DIAB_PPC
ACE_SOCKCALL_RETURN (::getpeername ((ACE_SOCKET) handle,
(struct sockaddr_in *) addr,
(ACE_SOCKET_LEN *) addrlen),
- int, -1);
-#else
+ int,
+ -1);
+# else
ACE_SOCKCALL_RETURN (::getpeername ((ACE_SOCKET) handle,
addr,
(ACE_SOCKET_LEN *) addrlen),
- int, -1);
-#endif /* defined (ACE_PSOS) */
+ int,
+ -1);
+# endif /* defined (ACE_PSOS) */
+#endif /* ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO */
}
ACE_INLINE int
@@ -196,17 +239,54 @@ ACE_OS::getsockname (ACE_HANDLE handle,
int *addrlen)
{
ACE_OS_TRACE ("ACE_OS::getsockname");
-#if defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC)
+#if defined (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO) \
+ && (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO == 1)
+ int result;
+# if defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC)
+ ACE_SOCKCALL (::getsockname ((ACE_SOCKET) handle,
+ (struct sockaddr_in *) addr,
+ (ACE_SOCKET_LEN *) addrlen),
+ int,
+ -1,
+ result);
+# else
+ ACE_SOCKCALL (::getsockname ((ACE_SOCKET) handle,
+ addr,
+ (ACE_SOCKET_LEN *) addrlen),
+ int, -1, result);
+# endif /* defined (ACE_PSOS) */
+
+ // Some platforms, like older versions of the Linux kernel, do not
+ // initialize the sin_zero field since that field is generally only
+ // used for padding/alignment purposes. On those platforms
+ // memcmp()-based comparisons of the sockaddr_in structure, such as
+ // the one in the ACE_INET_Addr equality operator, may fail due to
+ // random bytes in the sin_zero field even though that field is
+ // unused. Prevent equality comparison of two different sockaddr_in
+ // instances that refer to the same socket from failing by
+ // explicitly initializing the sockaddr_in::sin_zero field to a
+ // consistent value, e.g. zero.
+ if (result != -1 && addr->sa_family == AF_INET)
+ {
+ ACE_OS::memset (reinterpret_cast<struct sockaddr_in *> (addr),
+ 0,
+ sizeof (reinterpret_cast<struct sockaddr_in *> (addr)->sin_zero));
+ }
+
+ return result;
+#else
+# if defined (ACE_PSOS) && !defined (ACE_PSOS_DIAB_PPC)
ACE_SOCKCALL_RETURN (::getsockname ((ACE_SOCKET) handle,
(struct sockaddr_in *) addr,
(ACE_SOCKET_LEN *) addrlen),
int, -1);
-#else
+# else
ACE_SOCKCALL_RETURN (::getsockname ((ACE_SOCKET) handle,
addr,
(ACE_SOCKET_LEN *) addrlen),
int, -1);
-#endif /* defined (ACE_PSOS) */
+# endif /* defined (ACE_PSOS) */
+#endif /* ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO */
}
ACE_INLINE int
diff --git a/ace/README b/ace/README
index 8294d9fb4fb..f7962ee9393 100644
--- a/ace/README
+++ b/ace/README
@@ -29,7 +29,7 @@ ACE_DEFINES_DEFAULT_WIN32_SECURITY_ATTRIBUTES
Win32 only. Users want to use
a predefined security
attributes defined in
- ACE_OS::default_win32_security_attributes
+ ACE_OS::default_win32_security_attributes
as the default security
object.
ACE_DISABLE_DEBUG_DLL_CHECK Define this if you don't want
@@ -44,6 +44,15 @@ ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER
ACE_HAS_NONSTATIC_OBJECT_MANAGER.
Usually used with MFC
applications.
+ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO Platform does not initialize
+ sockaddr_in::sin_zero field in
+ calls to getpeername() and
+ getsockname(). As a result,
+ memcmp()-based equality
+ comparison can fail despite
+ the fact two sockaddr_in
+ instances refer to the same
+ addr characteristics.
ACE_MAIN Renames "main (int, char *[])",
for platforms such as g++/VxWorks
that don't allow "main". Requires
@@ -56,11 +65,14 @@ ACE_NEW_THROWS_EXCEPTIONS Compiler's 'new' throws exception on
ACE_NLOGGING Turns off the LM_DEBUG and
LM_ERROR logging macros...
ACE_NTRACE Turns off the tracing feature when = 1.
-ACE_HAS_TRACE Defined when ACE_NTRACE=0 to help support
- tracing. Can also be defined by users who
- implement their own tracing macros based on
- ACE_TRACE_IMPL. Not defining it helps reduce
- footprint by not requiring applications to
+ACE_HAS_TRACE Defined when ACE_NTRACE=0 to
+ help support tracing. Can
+ also be defined by users who
+ implement their own tracing
+ macros based on
+ ACE_TRACE_IMPL. Not defining
+ it helps reduce footprint by
+ not requiring applications to
link in Trace.o.
ACE_PAGE_SIZE Defines the page size of the
system (not used on Win32 or
@@ -90,16 +102,20 @@ ACE_USES_ASM_SYMBOL_IN_DLSYM Platform uses assembly symbols
ACE_USES_STATIC_MFC When linking MFC as a static library is desired
ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB Platform has its standard c++
library in the namespace std.
-ACE_USES_EXPLICIT_STD_NAMESPACE Set this when ::fclose doesn't work and you
- have to explicitly specify the std namespace.
- This is needed with the Borland 6 and earlier
+ACE_USES_EXPLICIT_STD_NAMESPACE Set this when ::fclose doesn't
+ work and you have to
+ explicitly specify the std
+ namespace. This is needed
+ with the Borland 6 and earlier
compilers.
ACE_USES_GPROF ACE calls getitimer before spawning
- a new thread and setitimer after spawning
- the thread in order to overcome the problems
- of gprof with multithreaded applications.
- It uses the idea from
- http://sam.zoy.org/writings/programming/gprof.html
+ a new thread and setitimer
+ after spawning the thread in
+ order to overcome the problems
+ of gprof with multithreaded
+ applications. It uses the
+ idea from
+ http://sam.zoy.org/writings/programming/gprof.html
ACE_WSOCK_VERSION A parameter list indicating
the version of WinSock (e.g.,
"1, 1" is version 1.1).
@@ -1000,9 +1016,10 @@ ACE_LACKS_WILDCARD_BIND The bind() call will not
ACE_LACKS_WRITEV Platform doesn't define
writev, so use our own
-ACE_LEGACY_MODE When defined, it will enable some code that is
- used to provide some support for backwards
- compatibility.
+ACE_LEGACY_MODE When defined, it will enable
+ some code that is used to
+ provide some support for
+ backwards compatibility.
ACE_NEEDS_DEV_IO_CONVERSION Necessary with some compilers
to pass ACE_TTY_IO as
@@ -1015,7 +1032,8 @@ ACE_NEEDS_FUNC_DEFINITIONS Compiler requires a definition
compiler needs this, in
template classes, with
ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA.
-ACE_NEEDS_HUGE_THREAD_STACKSIZE Required by platforms with small default stacks.
+ACE_NEEDS_HUGE_THREAD_STACKSIZE Required by platforms with
+ small default stacks.
ACE_NEEDS_LWP_PRIO_SET OS has LWPs, and when the
priority of a bound thread is
set, then the LWP priority
@@ -1031,15 +1049,22 @@ ACE_NO_WIN32_LEAN_AND_MEAN If this is set, then ACE does not
code that uses non-lean Win32
facilities such as COM.
-ACE_ONLY_LATEST_AND_GREATEST A macro that indicates that the "latest and greatest"
- features of ACE/TAO should be turned on. It has been
- replaced by ACE_LEGACY_MODE, which has the opposite
- meaning but serves the same purpose.
-
-ACE_WSTRING_HAS_USHORT_SUPPORT If a platform has wchar_t as a separate type,
- then ACE_WString doesn't have a constructor that
- understands an ACE_USHORT16 string. So this
- macro enables one. (mostly used my ACE Name Space).
+ACE_ONLY_LATEST_AND_GREATEST A macro that indicates that
+ the "latest and greatest"
+ features of ACE/TAO should be
+ turned on. It has been
+ replaced by ACE_LEGACY_MODE,
+ which has the opposite meaning
+ but serves the same purpose.
+
+ACE_WSTRING_HAS_USHORT_SUPPORT If a platform has wchar_t as a
+ separate type, then
+ ACE_WString doesn't have a
+ constructor that understands
+ an ACE_USHORT16 string. So
+ this macro enables
+ one. (mostly used my ACE Name
+ Space).
ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK
Under QNX/RTP the objects preallocated
@@ -1061,19 +1086,24 @@ The following macros determine the svc.conf file format ACE uses.
Macro Description
----- -----------
-ACE_HAS_CLASSIC_SVC_CONF This macro forces ACE to use the classic
- svc.conf format.
+ACE_HAS_CLASSIC_SVC_CONF This macro forces ACE to use
+ the classic svc.conf format.
ACE_HAS_XML_SVC_CONF This macro forces ACE to use the XML
svc.conf format.
-ACE_USES_CLASSIC_SVC_CONF This macro should be defined as 0 or 1, depending
- on the preferred svc.conf file format.
- Defining this macro to 0 means ACE will use XML
- svc.conf file format. Defining it to 1 will
- force ACE to use the classic svc.conf format.
- ** This macro takes precedence over previous
- ** two macros.
+ACE_USES_CLASSIC_SVC_CONF This macro should be defined
+ as 0 or 1, depending on the
+ preferred svc.conf file
+ format. Defining this macro
+ to 0 means ACE will use XML
+ svc.conf file format.
+ Defining it to 1 will force
+ ACE to use the classic
+ svc.conf format.
+ ** This macro takes precedence
+ ** over previous two macros.
+
----------------------------------------
The following is a partial list of where some of these macros are used
in the code. This list was originally compiled by Jam Hamidi
diff --git a/ace/config-linux-common.h b/ace/config-linux-common.h
index 8a719e77580..e5c1c3300ea 100644
--- a/ace/config-linux-common.h
+++ b/ace/config-linux-common.h
@@ -360,4 +360,17 @@
#include /**/ "ace/post.h"
+#if !defined (ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO)
+// detect if getsockname() and getpeername() returns
+// random values in the sin_zero field by evaluation
+// of the kernel version. since version 2.5.47
+// this problem is fixed.
+#include <linux/version.h>
+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,47))
+# define ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO 0
+# else
+# define ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO 1
+# endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0)) */
+#endif /* ACE_GETNAME_RETURNS_RANDOM_SIN_ZERO */
+
#endif /* ACE_LINUX_COMMON_H */