diff options
Diffstat (limited to 'ace/ACE.cpp')
-rw-r--r-- | ace/ACE.cpp | 1431 |
1 files changed, 0 insertions, 1431 deletions
diff --git a/ace/ACE.cpp b/ace/ACE.cpp index 0a43eaa9e49..c18c1a1415d 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -3,8 +3,6 @@ #include "ace/ACE.h" #include "ace/Handle_Set.h" #include "ace/Auto_Ptr.h" -#include "ace/INET_Addr.h" -#include "ace/Object_Manager.h" #include "ace/SString.h" #include "ace/Version.h" #include "ace/Message_Block.h" @@ -17,7 +15,6 @@ ACE_RCSID(ace, ACE, "$Id$") // Static data members. - u_int ACE::init_fini_count_ = 0; // Keeps track of whether we're in some global debug mode. char ACE::debug_ = 0; @@ -66,37 +63,6 @@ ACE::out_of_handles (int error) return 0; } -int -ACE::init (void) -{ - // Don't use ACE_TRACE, because Object_Manager might not have been - // instantiated yet. - // ACE_TRACE ("ACE::init"); - - ++init_fini_count_; - - return ACE_Object_Manager::instance ()->init (); -} - -int -ACE::fini (void) -{ - ACE_TRACE ("ACE::fini"); - - if (init_fini_count_ > 0) - { - if (--init_fini_count_ == 0) - return ACE_Object_Manager::instance ()->fini (); - else - // Wait for remaining fini () calls. - return 1; - } - else - // More ACE::fini () calls than ACE::init () calls. Bad - // application! - return -1; -} - u_int ACE::major_version (void) { @@ -240,77 +206,6 @@ ACE::process_active (pid_t pid) #endif /* ACE_HAS_PACE */ } -// Split a string up into 'token'-delimited pieces, ala Perl's -// "split". - -char * -ACE::strsplit_r (char *str, - const char *token, - char *&next_start) -{ - char *result = 0; - - if (str != 0) - next_start = str; - - if (next_start != 0) - { - char *tok_loc = ACE_OS::strstr (next_start, token); - - if (tok_loc != 0) - { - // Return the beginning of the string. - result = next_start; - - // Insure it's terminated. - *tok_loc = '\0'; - next_start = tok_loc + ACE_OS::strlen (token); - } - else - { - result = next_start; - next_start = (char *) 0; - } - } - - return result; -} - -#if defined (ACE_HAS_WCHAR) -wchar_t * -ACE::strsplit_r (wchar_t *str, - const wchar_t *token, - wchar_t *&next_start) -{ - wchar_t *result = 0; - - if (str != 0) - next_start = str; - - if (next_start != 0) - { - wchar_t *tok_loc = ACE_OS::strstr (next_start, token); - - if (tok_loc != 0) - { - // Return the beginning of the string. - result = next_start; - - // Insure it's terminated. - *tok_loc = '\0'; - next_start = tok_loc + ACE_OS::strlen (token); - } - else - { - result = next_start; - next_start = (wchar_t *) 0; - } - } - - return result; -} -#endif - const ACE_TCHAR * ACE::execname (const ACE_TCHAR *old_name) { @@ -548,23 +443,6 @@ ACE::crc32 (const char *buffer, ACE_UINT32 len) #undef COMPUTE -size_t -ACE::strrepl (char *s, char search, char replace) -{ - ACE_TRACE ("ACE::strrepl"); - - size_t replaced = 0; - - for (size_t i = 0; s[i] != '\0'; i++) - if (s[i] == search) - { - s[i] = replace; - replaced++; - } - - return replaced; -} - #if defined (ACE_HAS_WCHAR) size_t ACE::strrepl (wchar_t *s, wchar_t search, wchar_t replace) @@ -612,445 +490,6 @@ netsvc.so netsvc.so + warning libnetsvc.so */ -#if ! defined (ACE_PSOS_DIAB_MIPS) -int -ACE::ldfind (const ACE_TCHAR filename[], - ACE_TCHAR pathname[], - size_t maxpathnamelen) -{ - ACE_TRACE ("ACE::ldfind"); - -#if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && \ - !defined (ACE_HAS_PHARLAP) - ACE_TCHAR expanded_filename[MAXPATHLEN]; - if (ACE_TEXT_ExpandEnvironmentStrings (filename, - expanded_filename, - sizeof expanded_filename - / sizeof (ACE_TCHAR))) - filename = expanded_filename; -#endif /* ACE_WIN32 && !ACE_HAS_WINCE && !ACE_HAS_PHARLAP */ - - ACE_TCHAR tempcopy[MAXPATHLEN + 1]; - ACE_TCHAR searchpathname[MAXPATHLEN + 1]; - ACE_TCHAR searchfilename[MAXPATHLEN + 2]; - - // Create a copy of filename to work with. - if (ACE_OS::strlen (filename) + 1 - > (sizeof tempcopy / sizeof (ACE_TCHAR))) - { - errno = ENOMEM; - return -1; - } - else - ACE_OS::strcpy (tempcopy, filename); - - // Insert canonical directory separators. - ACE_TCHAR *separator_ptr; - -#if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') - // Make all the directory separators "canonical" to simplify - // subsequent code. - ACE::strrepl (tempcopy, ACE_DIRECTORY_SEPARATOR_CHAR, '/'); -#endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ - - // Separate filename from pathname. - separator_ptr = ACE_OS::strrchr (tempcopy, '/'); - - // This is a relative path. - if (separator_ptr == 0) - { - searchpathname[0] = '\0'; - ACE_OS::strcpy (searchfilename, tempcopy); - } - else // This is an absolute path. - { - ACE_OS::strcpy (searchfilename, separator_ptr + 1); - separator_ptr[1] = '\0'; - ACE_OS::strcpy (searchpathname, tempcopy); - } - - int got_suffix = 0; - - // Check to see if this has an appropriate DLL suffix for the OS - // platform. - ACE_TCHAR *s = ACE_OS::strrchr (searchfilename, '.'); - - const ACE_TCHAR *dll_suffix = ACE_DLL_SUFFIX; - - if (s != 0) - { - // If we have a dot, we have a suffix - got_suffix = 1; - - // Check whether this matches the appropriate platform-specific - // suffix. - if (ACE_OS::strcmp (s, dll_suffix) != 0) - { - ACE_ERROR ((LM_WARNING, - ACE_LIB_TEXT ("Warning: improper suffix for a ") - ACE_LIB_TEXT ("shared library on this platform: %s\n"), - s)); - } - } - - // Make sure we've got enough space in searchfilename. - if (ACE_OS::strlen (searchfilename) - + ACE_OS::strlen (ACE_DLL_PREFIX) - + got_suffix ? 0 : ACE_OS::strlen (dll_suffix) >= (sizeof searchfilename / - sizeof (ACE_TCHAR))) - { - errno = ENOMEM; - return -1; - } - -#if defined (ACE_WIN32) && defined (_DEBUG) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) - size_t len_searchfilename = ACE_OS::strlen (searchfilename); - if (! got_suffix) - { - searchfilename [len_searchfilename] = 'd'; - searchfilename [len_searchfilename+1] = 0; - } - - for (int tag = 1; tag >= 0; tag --) - { - if (tag == 0) - searchfilename [len_searchfilename] = 0; - -#endif /* ACE_WIN32 && _DEBUG && !ACE_DISABLE_DEBUG_DLL_CHECK */ - // Use absolute pathname if there is one. - if (ACE_OS::strlen (searchpathname) > 0) - { - if (ACE_OS::strlen (searchfilename) - + ACE_OS::strlen (searchpathname) >= maxpathnamelen) - { - errno = ENOMEM; - return -1; - } - else - { -#if (ACE_DIRECTORY_SEPARATOR_CHAR != '/') - // Revert to native path name separators. - ACE::strrepl (searchpathname, - '/', - ACE_DIRECTORY_SEPARATOR_CHAR); -#endif /* ACE_DIRECTORY_SEPARATOR_CHAR */ - // First, try matching the filename *without* adding a - // prefix. -#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%s%s"), - searchpathname, - searchfilename, - got_suffix ? ACE_static_cast (ACE_TCHAR *, - ACE_LIB_TEXT ("")) - : ACE_static_cast (ACE_TCHAR *, - dll_suffix)); -#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%s%s"), - searchpathname, - searchfilename, - got_suffix ? ACE_LIB_TEXT ("") : dll_suffix); -#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - if (ACE_OS::access (pathname, F_OK) == 0) - return 0; - - // Second, try matching the filename *with* adding a prefix. -#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%s%s%s"), - searchpathname, - ACE_DLL_PREFIX, - searchfilename, - got_suffix ? ACE_static_cast (ACE_TCHAR *, - ACE_LIB_TEXT ("")) - : ACE_static_cast (ACE_TCHAR *, - dll_suffix)); -#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%s%s%s"), - searchpathname, - ACE_DLL_PREFIX, - searchfilename, - got_suffix ? ACE_LIB_TEXT ("") : dll_suffix); -#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - if (ACE_OS::access (pathname, F_OK) == 0) - return 0; - } - } - - // Use relative filenames via LD_LIBRARY_PATH or PATH (depending on - // OS platform). - else - { - ACE_TCHAR *ld_path = -#if defined ACE_DEFAULT_LD_SEARCH_PATH - ACE_DEFAULT_LD_SEARCH_PATH; -#else - ACE_OS::getenv (ACE_LD_SEARCH_PATH); -#endif /* ACE_DEFAULT_LD_SEARCH_PATH */ - -#if defined (ACE_WIN32) - ACE_TCHAR *ld_path_temp = 0; - if (ld_path != 0) - { - ld_path_temp = (ACE_TCHAR *) ACE_OS::malloc ((ACE_OS::strlen (ld_path) + 2) - * sizeof (ACE_TCHAR)); - if (ld_path_temp != 0) - { - ACE_OS::strcpy (ld_path_temp, ACE_LD_SEARCH_PATH_SEPARATOR_STR); - ACE_OS::strcat (ld_path_temp, ld_path); - ld_path = ld_path_temp; - } - else - { - ACE_OS::free ((void *) ld_path_temp); - ld_path = ld_path_temp = 0; - } - } -#endif /* ACE_WIN32 */ - - if (ld_path != 0 - && (ld_path = ACE_OS::strdup (ld_path)) != 0) - { - // strtok has the strange behavior of not separating the - // string ":/foo:/bar" into THREE tokens. One would expect - // that the first iteration the token would be an empty - // string, the second iteration would be "/foo", and the - // third iteration would be "/bar". However, this is not - // the case; one only gets two iterations: "/foo" followed - // by "/bar". - - // This is especially a problem in parsing Unix paths - // because it is permissible to specify 'the current - // directory' as an empty entry. So, we introduce the - // following special code to cope with this: - - // Look at each dynamic lib directory in the search path. - - ACE_TCHAR *nextholder = 0; - const ACE_TCHAR *path_entry = - ACE::strsplit_r (ld_path, - ACE_LD_SEARCH_PATH_SEPARATOR_STR, - nextholder); - int result = 0; - - for (;;) - { - // Check if at end of search path. - if (path_entry == 0) - { - errno = ENOENT; - result = -1; - break; - } - else if (ACE_OS::strlen (path_entry) - + 1 - + ACE_OS::strlen (searchfilename) - >= maxpathnamelen) - { - errno = ENOMEM; - result = -1; - break; - } - // This works around the issue where a path might have - // an empty component indicating 'current directory'. - // We need to do it here rather than anywhere else so - // that the loop condition will still work. - else if (path_entry[0] == '\0') - path_entry = ACE_LIB_TEXT ("."); - - // First, try matching the filename *without* adding a - // prefix. -#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%c%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, - searchfilename, - got_suffix ? ACE_static_cast (ACE_TCHAR *, - ACE_LIB_TEXT ("")) - : ACE_static_cast (ACE_TCHAR *, - dll_suffix)); -#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%c%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, - searchfilename, - got_suffix ? ACE_LIB_TEXT ("") : dll_suffix); -#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - if (ACE_OS::access (pathname, F_OK) == 0) - break; - - // Second, try matching the filename *with* adding a - // prefix. -#if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%c%s%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, - ACE_DLL_PREFIX, - searchfilename, - got_suffix ? ACE_static_cast (ACE_TCHAR *, - ACE_LIB_TEXT ("")) - : ACE_static_cast (ACE_TCHAR *, - dll_suffix)); -#else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - ACE_OS::sprintf (pathname, - ACE_LIB_TEXT ("%s%c%s%s%s"), - path_entry, - ACE_DIRECTORY_SEPARATOR_CHAR, - ACE_DLL_PREFIX, - searchfilename, - got_suffix ? ACE_LIB_TEXT ("") : dll_suffix); -#endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */ - if (ACE_OS::access (pathname, F_OK) == 0) - break; - - // Fetch the next item in the path - path_entry = ACE::strsplit_r (0, - ACE_LD_SEARCH_PATH_SEPARATOR_STR, - nextholder); - } - -#if defined (ACE_WIN32) - if (ld_path_temp != 0) - ACE_OS::free (ld_path_temp); -#endif /* ACE_WIN32 */ - ACE_OS::free ((void *) ld_path); -#if defined (ACE_WIN32) && defined (_DEBUG) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) - if (result == 0 || tag == 0) -#endif /* ACE_WIN32 && _DEBUG && !ACE_DISABLE_DEBUG_DLL_CHECK */ - return result; - } - } -#if defined (ACE_WIN32) && defined (_DEBUG) && !defined (ACE_DISABLE_DEBUG_DLL_CHECK) - } -#endif /* ACE_WIN32 && _DEBUG && !ACE_DISABLE_DEBUG_DLL_CHECK */ - - errno = ENOENT; - return -1; -} - -FILE * -ACE::ldopen (const ACE_TCHAR *filename, - const ACE_TCHAR *type) -{ - ACE_TRACE ("ACE::ldopen"); - - ACE_TCHAR buf[MAXPATHLEN + 1]; - if (ACE::ldfind (filename, - buf, - sizeof (buf) /sizeof (ACE_TCHAR)) == -1) - return 0; - else - return ACE_OS::fopen (buf, type); -} - -ACE_TCHAR * -ACE::ldname (const ACE_TCHAR *entry_point) -{ - ACE_TRACE ("ACE::ldname"); - -#if defined (__BORLANDC__) - size_t size = - 1 // leading '_' - + ACE_OS::strlen (entry_point) - + 1; - - ACE_TCHAR *new_name; - ACE_NEW_RETURN (new_name, - ACE_TCHAR[size], - 0); - - ACE_OS::strcpy (new_name, ACE_LIB_TEXT ("_")); - ACE_OS::strcat (new_name, entry_point); - - return new_name; -#else /* __BORLANDC__ */ - size_t size = - ACE_OS::strlen (entry_point) - + 1; - - ACE_TCHAR *new_name; - ACE_NEW_RETURN (new_name, - ACE_TCHAR[size], - 0); - - ACE_OS::strcpy (new_name, entry_point); - - return new_name; -#endif /* __BORLANDC__ */ -} - -int -ACE::get_temp_dir (ACE_TCHAR *buffer, size_t buffer_len) -{ - int result; -#if defined (ACE_WIN32) - result = ACE_TEXT_GetTempPath (buffer_len, buffer); - - // Make sure to return -1 if there is an error - if (result == 0 && ::GetLastError () != ERROR_SUCCESS - || result > ACE_static_cast (int, buffer_len)) - result = -1; - -#else /* ACE_WIN32 */ - - // On non-win32 platforms, check to see what the TMPDIR environment - // variable is defined to be. If it doesn't exist, just use /tmp - const ACE_TCHAR *tmpdir = ACE_OS::getenv (ACE_LIB_TEXT ("TMPDIR")); - - if (tmpdir == NULL) - tmpdir = ACE_LIB_TEXT ("/tmp"); - - size_t len = ACE_OS::strlen (tmpdir); - - // Check to see if the buffer is large enough for the string, - // another /, and its null character (hence the + 2) - if ((len + 2) > buffer_len) - { - result = -1; - } - else - { - ACE_OS::strcpy (buffer, tmpdir); - - // Add a trailing slash because we cannot assume there is already one - // at the end. And having an extra one should not cause problems. - buffer[len] = '/'; - buffer[len + 1] = 0; - result = 0; - } -#endif /* ACE_WIN32 */ - return result; -} - -ACE_HANDLE -ACE::open_temp_file (const ACE_TCHAR *name, int mode, int perm) -{ -#if defined (ACE_WIN32) - return ACE_OS::open (name, - mode | _O_TEMPORARY); -#else - // Open it. - ACE_HANDLE handle = ACE_OS::open (name, mode, perm); - - if (handle == ACE_INVALID_HANDLE) - return ACE_INVALID_HANDLE; - - // Unlink it so that the file will be removed automatically when the - // process goes away. - if (ACE_OS::unlink (name) == -1) - return -1; - else - // Return the handle. - return handle; -#endif /* ACE_WIN32 */ -} -#endif /* ! ACE_PSOS_DIAB_MIPS */ - const ACE_TCHAR * ACE::basename (const ACE_TCHAR *pathname, ACE_TCHAR delim) { @@ -3185,32 +2624,6 @@ ACE::handle_timed_complete (ACE_HANDLE h, return h; } -ACE_HANDLE -ACE::handle_timed_open (ACE_Time_Value *timeout, - const ACE_TCHAR *name, - int flags, - int perms) -{ - ACE_TRACE ("ACE::handle_timed_open"); - - if (timeout != 0) - { - // Open the named pipe or file using non-blocking mode... - ACE_HANDLE handle = ACE_OS::open (name, - flags | ACE_NONBLOCK, - perms); - if (handle == ACE_INVALID_HANDLE - && (errno == EWOULDBLOCK - && (timeout->sec () > 0 || timeout->usec () > 0))) - // This expression checks if we were polling. - errno = ETIMEDOUT; - - return handle; - } - else - return ACE_OS::open (name, flags, perms); -} - // Wait up to <timeout> amount of time to accept a connection. int @@ -3280,70 +2693,6 @@ ACE::handle_timed_accept (ACE_HANDLE listener, ACE_NOTREACHED (return 0); } -// Bind socket to an unused port. - -int -ACE::bind_port (ACE_HANDLE handle, - ACE_UINT32 ip_addr) -{ - ACE_TRACE ("ACE::bind_port"); - - sockaddr_in sock_addr; - - ACE_OS::memset ((void *) &sock_addr, 0, sizeof sock_addr); - sock_addr.sin_family = AF_INET; -#if defined (ACE_HAS_SIN_LEN) - sock_addr.sin_len = sizeof sock_addr; -#endif /* ACE_HAS_SIN_LEN */ - sock_addr.sin_addr.s_addr = ip_addr; - -#if !defined (ACE_LACKS_WILDCARD_BIND) - // The OS kernel should select a free port for us. - sock_addr.sin_port = 0; - return ACE_OS::bind (handle, - ACE_reinterpret_cast(sockaddr *, &sock_addr), - sizeof sock_addr); -#else - static u_short upper_limit = ACE_MAX_DEFAULT_PORT; - int round_trip = upper_limit; - int lower_limit = IPPORT_RESERVED; - - // We have to select the port explicitly. - - for (;;) - { - sock_addr.sin_port = htons (upper_limit); - - if (ACE_OS::bind (handle, - ACE_reinterpret_cast(sockaddr *, &sock_addr), - sizeof sock_addr) >= 0) - { -#if defined (ACE_WIN32) - upper_limit--; -#endif /* ACE_WIN32 */ - return 0; - } - else if (errno != EADDRINUSE) - return -1; - else - { - upper_limit--; - - // Wrap back around when we reach the bottom. - if (upper_limit <= lower_limit) - upper_limit = ACE_MAX_DEFAULT_PORT; - - // See if we have already gone around once! - if (upper_limit == round_trip) - { - errno = EAGAIN; - return -1; - } - } - } -#endif /* ACE_HAS_WILDCARD_BIND */ -} - // Make the current process a UNIX daemon. This is based on Stevens // code from APUE. @@ -3539,77 +2888,6 @@ ACE::set_handle_limit (int new_limit) ACE_NOTREACHED (return 0); } -// Flags are file status flags to turn on. - -int -ACE::set_flags (ACE_HANDLE handle, int flags) -{ - ACE_TRACE ("ACE::set_flags"); -#if defined (ACE_WIN32) || defined (VXWORKS) || defined (ACE_LACKS_FCNTL) - switch (flags) - { - case ACE_NONBLOCK: - // nonblocking argument (1) - // blocking: (0) - { - u_long nonblock = 1; - return ACE_OS::ioctl (handle, FIONBIO, &nonblock); - } - default: - ACE_NOTSUP_RETURN (-1); - } -#else - int val = ACE_OS::fcntl (handle, F_GETFL, 0); - - if (val == -1) - return -1; - - // Turn on flags. - ACE_SET_BITS (val, flags); - - if (ACE_OS::fcntl (handle, F_SETFL, val) == -1) - return -1; - else - return 0; -#endif /* ACE_WIN32 || ACE_LACKS_FCNTL */ -} - -// Flags are the file status flags to turn off. - -int -ACE::clr_flags (ACE_HANDLE handle, int flags) -{ - ACE_TRACE ("ACE::clr_flags"); - -#if defined (ACE_WIN32) || defined (VXWORKS) || defined (ACE_LACKS_FCNTL) - switch (flags) - { - case ACE_NONBLOCK: - // nonblocking argument (1) - // blocking: (0) - { - u_long nonblock = 0; - return ACE_OS::ioctl (handle, FIONBIO, &nonblock); - } - default: - ACE_NOTSUP_RETURN (-1); - } -#else - int val = ACE_OS::fcntl (handle, F_GETFL, 0); - - if (val == -1) - return -1; - - // Turn flags off. - ACE_CLR_BITS (val, flags); - - if (ACE_OS::fcntl (handle, F_SETFL, val) == -1) - return -1; - else - return 0; -#endif /* ACE_WIN32 || ACE_LACKS_FCNTL */ -} - int ACE::map_errno (int error) { @@ -3805,306 +3083,6 @@ ACE::sock_error (int error) #endif /* ACE_WIN32 */ } -int -ACE::get_bcast_addr (ACE_UINT32 &bcast_addr, - const ACE_TCHAR *host_name, - ACE_UINT32 host_addr, - ACE_HANDLE handle) -{ - ACE_TRACE ("ACE::get_bcast_addr"); - -#if !defined(ACE_WIN32) - ACE_HANDLE s = handle; - - if (s == ACE_INVALID_HANDLE) - s = ACE_OS::socket (AF_INET, SOCK_STREAM, 0); - - if (s == ACE_INVALID_HANDLE) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE_OS::socket")), - -1); - - struct ifconf ifc; - char buf[BUFSIZ]; - - ifc.ifc_len = sizeof buf; - ifc.ifc_buf = buf; - - // Get interface structure and initialize the addresses using UNIX - // techniques -#if defined (AIX) - int cmd = CSIOCGIFCONF; -#else - int cmd = SIOCGIFCONF; -#endif /* AIX */ - if (ACE_OS::ioctl (s, cmd, (char *) &ifc) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_bcast_addr:") - ACE_LIB_TEXT ("ioctl (get interface configuration)")), - -1); - - struct ifreq *ifr = ifc.ifc_req; - - struct sockaddr_in ip_addr; - - // Get host ip address if necessary. - if (host_name) - { - hostent *hp = ACE_OS::gethostbyname (host_name); - - if (hp == 0) - return -1; - else -#if !defined(_UNICOS) - ACE_OS::memcpy ((char *) &ip_addr.sin_addr.s_addr, - (char *) hp->h_addr, - hp->h_length); -#else /* _UNICOS */ - { - ACE_UINT64 haddr; // a place to put the address - char * haddrp = (char *) &haddr; // convert to char pointer - ACE_OS::memcpy(haddrp,(char *) hp->h_addr,hp->h_length); - ip_addr.sin_addr.s_addr = haddr; - } -#endif /* ! _UNICOS */ - } - else - { - ACE_OS::memset ((void *) &ip_addr, 0, sizeof ip_addr); -#if !defined(_UNICOS) - ACE_OS::memcpy ((void *) &ip_addr.sin_addr, - (void*) &host_addr, - sizeof ip_addr.sin_addr); -#else /* _UNICOS */ - ip_addr.sin_addr.s_addr = host_addr; // just copy to the bitfield -#endif /* ! _UNICOS */ - } - - for (int n = ifc.ifc_len / sizeof (struct ifreq); - n > 0; -#if !defined(CHORUS_4) - n--, ifr++) -#else - n--, - ((ifr->ifr_addr.sa_len <= sizeof (struct sockaddr)) ? - ifr++ : - ifr = (struct ifreq *) - (ifr->ifr_addr.sa_len + (caddr_t) &ifr->ifr_addr))) -#endif /* CHORUS_4 */ - { - struct sockaddr_in if_addr; - - // Compare host ip address with interface ip address. - ACE_OS::memcpy (&if_addr, - &ifr->ifr_addr, - sizeof if_addr); - - if (ip_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr) - continue; - - if (ifr->ifr_addr.sa_family != AF_INET) - { - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_bcast_addr:") - ACE_LIB_TEXT ("Not AF_INET"))); - continue; - } - - struct ifreq flags = *ifr; - struct ifreq if_req = *ifr; - - if (ACE_OS::ioctl (s, SIOCGIFFLAGS, (char *) &flags) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_bcast_addr:") - ACE_LIB_TEXT (" ioctl (get interface flags)"))); - continue; - } - - if (ACE_BIT_DISABLED (flags.ifr_flags, IFF_UP)) - { - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_bcast_addr:") - ACE_LIB_TEXT ("Network interface is not up"))); - continue; - } - - if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_LOOPBACK)) - continue; - - if (ACE_BIT_ENABLED (flags.ifr_flags, IFF_BROADCAST)) - { - if (ACE_OS::ioctl (s, - SIOCGIFBRDADDR, - (char *) &if_req) == -1) - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_bcast_addr:") - ACE_LIB_TEXT ("ioctl (get broadaddr)"))); - else - { - ACE_OS::memcpy (ACE_reinterpret_cast(sockaddr_in *, &ip_addr), - ACE_reinterpret_cast(sockaddr_in *, &if_req.ifr_broadaddr), - sizeof if_req.ifr_broadaddr); - - ACE_OS::memcpy ((void *) &host_addr, - (void *) &ip_addr.sin_addr, - sizeof host_addr); - - if (handle == ACE_INVALID_HANDLE) - ACE_OS::close (s); - - bcast_addr = host_addr; - return 0; - } - } - else - ACE_ERROR ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_bcast_addr:") - ACE_LIB_TEXT ("Broadcast is not enable for this interface."))); - - if (handle == ACE_INVALID_HANDLE) - ACE_OS::close (s); - - bcast_addr = host_addr; - return 0; - } - - return 0; -#else - ACE_UNUSED_ARG (handle); - ACE_UNUSED_ARG (host_addr); - ACE_UNUSED_ARG (host_name); - bcast_addr = (ACE_UINT32 (INADDR_BROADCAST)); - return 0; -#endif /* !ACE_WIN32 */ -} - -// Helper routine for get_ip_interfaces, differs by UNIX platform so -// put into own subroutine. perform some ioctls to retrieve ifconf -// list of ifreq structs. - -int -ACE::count_interfaces (ACE_HANDLE handle, - size_t &how_many) -{ -#if defined (sparc) && defined (SIOCGIFNUM) - int tmp_how_many; // For 64 bit Solaris - if (ACE_OS::ioctl (handle, - SIOCGIFNUM, - (caddr_t) &tmp_how_many) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_LIB_TEXT ("ACE::get_ip_interfaces:") - ACE_LIB_TEXT ("ioctl - SIOCGIFNUM failed")), - -1); - how_many = (size_t) tmp_how_many; - return 0; -#elif defined (__unix) || defined (__Lynx__) || defined (_AIX) - // Note: DEC CXX doesn't define "unix". BSD compatible OS: HP UX, - // AIX, SunOS 4.x perform some ioctls to retrieve ifconf list of - // ifreq structs no SIOCGIFNUM on SunOS 4.x, so use guess and scan - // algorithm - - // Probably hard to put this many ifs in a unix box.. - const int MAX_IF = 50; - - // HACK - set to an unreasonable number - int num_ifs = MAX_IF; - - struct ifconf ifcfg; - size_t ifreq_size = num_ifs * sizeof (struct ifreq); - struct ifreq *p_ifs = - (struct ifreq *) ACE_OS::malloc (ifreq_size); - - if (!p_ifs) - { - errno = ENOMEM; - return -1; - } - - ACE_OS::memset (p_ifs, 0, ifreq_size); - ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf)); - - ifcfg.ifc_req = p_ifs; - ifcfg.ifc_len = ifreq_size; - -#if defined (AIX) - int cmd = CSIOCGIFCONF; -#else - int cmd = SIOCGIFCONF; -#endif /* AIX */ - if (ACE_OS::ioctl (handle, - cmd, - (caddr_t) &ifcfg) == -1) - { - ACE_OS::free (ifcfg.ifc_req); - ACE_ERROR_RETURN ((LM_ERROR, - ACE_LIB_TEXT ("count_interfaces:ioctl:") - ACE_LIB_TEXT ("SIOCGIFCONF failed")), - -1); - } - - int if_count = 0, i; - - // get if address out of ifreq buffers. ioctl puts a blank-named - // interface to mark the end of the returned interfaces. - for (i = 0; - i < num_ifs; - i++) - { - if (p_ifs->ifr_name[0] == '\0') - break; - - if_count++; -#if !defined(CHORUS_4) - p_ifs++; -#else - if (p_ifs->ifr_addr.sa_len <= sizeof (struct sockaddr)) - { - p_ifs++; - } - else - { - p_ifs = (struct ifreq *) - (p_ifs->ifr_addr.sa_len + (caddr_t) &p_ifs->ifr_addr); - } -#endif /* CHORUS_4 */ - } - - ACE_OS::free (ifcfg.ifc_req); - how_many = if_count; - return 0; -#else - ACE_UNUSED_ARG (handle); - ACE_UNUSED_ARG (how_many); - ACE_NOTSUP_RETURN (-1);; // no implmentation -#endif /* sparc && SIOCGIFNUM */ -} - -// Routine to return a handle from which ioctl() requests can be made. - -ACE_HANDLE -ACE::get_handle (void) -{ - // Solaris 2.x - ACE_HANDLE handle = ACE_INVALID_HANDLE; -#if defined (sparc) && ! defined (CHORUS) - handle = ACE_OS::open ("/dev/udp", O_RDONLY); -#elif defined (__unix) || defined (__Lynx__) || defined (_AIX) - // Note: DEC CXX doesn't define "unix" BSD compatible OS: HP UX, - // AIX, SunOS 4.x - - handle = ACE_OS::socket (PF_INET, SOCK_DGRAM, 0); -#endif /* sparc */ - return handle; -} - #if defined (ACE_WIN32) // Return value in buffer for a key/name pair from the Windows // Registry up to buf_len size. @@ -4145,384 +3123,6 @@ get_reg_value (const ACE_TCHAR *key, } #endif /* ACE_WIN32 */ -// return an array of all configured IP interfaces on this host, count -// rc = 0 on success (count == number of interfaces else -1 caller is -// responsible for calling delete [] on parray - -int -ACE::get_ip_interfaces (size_t &count, - ACE_INET_Addr *&addrs) -{ - ACE_TRACE ("ACE::get_ip_interfaces"); - - count = 0; - addrs = 0; - -#if defined (ACE_WIN32) - // Win32 can do this by a simple API call if MSVC 5 or later is the compiler. - // Not sure if Borland supplies the needed header/lib, but it might. -# if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) -#if 0 - // If this also needs to be predicated on MSVC 5 or later, add the - // following condition to the #if above. It tests ok at Riverace w/ 4.2, - // but this isn't a virgin install of 4.2 so there's a minimal risk that - // it may need work later. - defined (_MSC_VER) && (_MSC_VER >= 1100) -#endif /* 0 */ - - int i, n_interfaces, status; - INTERFACE_INFO info[64]; - LPINTERFACE_INFO lpii; - SOCKET sock; - - // Get an (overlapped) DGRAM socket to test with - sock = socket (AF_INET, SOCK_DGRAM, 0); - if (sock == INVALID_SOCKET) - return -1; - - DWORD bytes; - status = WSAIoctl(sock, - SIO_GET_INTERFACE_LIST, - 0, 0, - info, sizeof(info), - &bytes, - 0, - 0); - closesocket (sock); - if (status == SOCKET_ERROR) - return -1; - - n_interfaces = bytes / sizeof(INTERFACE_INFO); - if (n_interfaces == 0) - return 0; - - ACE_NEW_RETURN (addrs, - ACE_INET_Addr[n_interfaces], - -1); - - // Now go through the list and transfer the good ones to the list of - // because they're down or don't have an IP address. - for (count = 0, i = 0; i < n_interfaces; i++) - { - struct sockaddr_in *addrp; - - lpii = &info[i]; - if (!(lpii->iiFlags & IFF_UP)) - continue; - - // We assume IPv4 addresses here - addrp = ACE_reinterpret_cast(struct sockaddr_in *, &(lpii->iiAddress)); - if (addrp->sin_addr.s_addr == INADDR_ANY) - continue; - - // Set the address for the caller. - addrs[count].set(addrp, sizeof(lpii->iiAddress)); - ++count; - } - - if (count == 0) - { - delete [] addrs; - addrs = 0; - } - - return 0; - -#else /* Winsock 2 && MSVC 5 or later */ - - // PharLap ETS has kernel routines to rummage through the device - // configs and extract the interface info. Sort of a pain in the - // butt, but better than trying to figure out where it moved to in - // the registry... :-| -# if defined (ACE_HAS_PHARLAP) -# if !defined (ACE_HAS_PHARLAP_RT) - ACE_NOTSUP_RETURN (-1); -# endif /* ACE_HAS_PHARLAP_RT */ - - // Locate all of the IP devices in the system, saving a DEVHANDLE - // for each. Then allocate the ACE_INET_Addrs needed and fetch all - // the IP addresses. To locate the devices, try the available - // device name roots and increment the device number until the - // kernel says there are no more of that type. - const size_t ACE_MAX_ETS_DEVICES = 64; // Arbitrary, but should be enough. - DEVHANDLE ip_dev[ACE_MAX_ETS_DEVICES]; - EK_TCPIPCFG *devp; - size_t i, j; - ACE_TCHAR dev_name[16]; - - count = 0; - for (i = 0; count < ACE_MAX_ETS_DEVICES; i++, ++count) - { - // Ethernet. - ACE_OS::sprintf (dev_name, - "ether%d", - i); - ip_dev[count] = EtsTCPGetDeviceHandle (dev_name); - if (ip_dev[count] == 0) - break; - } - for (i = 0; count < ACE_MAX_ETS_DEVICES; i++, ++count) - { - // SLIP. - ACE_OS::sprintf (dev_name, - "sl%d", - i); - ip_dev[count] = EtsTCPGetDeviceHandle (dev_name); - if (ip_dev[count] == 0) - break; - } - for (i = 0; count < ACE_MAX_ETS_DEVICES; i++, ++count) - { - // PPP. - ACE_OS::sprintf (dev_name, - "ppp%d", - i); - ip_dev[count] = EtsTCPGetDeviceHandle (dev_name); - if (ip_dev[count] == 0) - break; - } - - if (count > 0) - ACE_NEW_RETURN (addrs, - ACE_INET_Addr[count], - -1); - else - addrs = 0; - - for (i = 0, j = 0; i < count; i++) - { - devp = EtsTCPGetDeviceCfg (ip_dev[i]); - if (devp != 0) - { - addrs[j].set (0, - devp->nwIPAddress, - 0); // Already in net order. - j++; - } - // There's no call to close the DEVHANDLE. - } - - count = j; - if (count == 0 && addrs != 0) - { - delete [] addrs; - addrs = 0; - } - - return 0; - -# else /* ACE_HAS_PHARLAP */ - - const ACE_TCHAR *SVCS_KEY1 = - ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services\\"); - const ACE_TCHAR *LINKAGE_KEY1 = - ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage"); - const ACE_TCHAR *TCP_PARAM_SUBKEY = ACE_LIB_TEXT ("\\Parameters\\Tcpip"); - const ACE_TCHAR *BIND_NAME_ID = ACE_LIB_TEXT ("Bind"); - const ACE_TCHAR *IPADDR_NAME_ID = ACE_LIB_TEXT ("IPAddress"); - const ACE_TCHAR *INVALID_TCPIP_DEVICE_ADDR = ACE_LIB_TEXT ("0.0.0.0"); - - ACE_TCHAR raw_buffer[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1]; - DWORD raw_buflen = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1; - ACE_TCHAR buffer[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1]; - DWORD buf_len = ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 1; - - if (::get_reg_value (LINKAGE_KEY1, - BIND_NAME_ID, - raw_buffer, - raw_buflen)) - return -1; - // return buffer contains 0 delimited strings - - ACE_Tokenizer dev_names (raw_buffer); - dev_names.delimiter (ACE_LIB_TEXT ('\0')); - int n_interfaces = 0; - - // Count the number of interfaces - while (dev_names.next () != 0) - n_interfaces ++; - - // case 1. no interfaces present, empty string? OS version change? - if (n_interfaces == 0) - return 0; - - ACE_NEW_RETURN (addrs, - ACE_INET_Addr[n_interfaces], - -2); - count = 0; - for (int i = 0; i < n_interfaces; i++) - { - // a. construct name to access IPAddress for this interface - ACE_TString ifdevkey (SVCS_KEY1); - ACE_TString the_dev = dev_names.next (); - - // chop off the "\Device" and keep last name. - if (the_dev.length() < 8) - return -3; // Something's wrong - else - { - // rest of string from offset 8 - the_dev = the_dev.substring (8); - ifdevkey += the_dev; - ifdevkey += TCP_PARAM_SUBKEY; - - // b. extract value - // Gets overwritten on each call - buf_len = sizeof(buffer); - if (get_reg_value (ifdevkey.fast_rep (), - IPADDR_NAME_ID, - buffer, - buf_len)) - return -4; - - if (ACE_OS::strcmp (buffer, - INVALID_TCPIP_DEVICE_ADDR) == 0) - continue; // Don't count this device - - // c. store in hostinfo object array and up the counter - addrs[count++] = - ACE_INET_Addr ((u_short) 0, buffer); - } - } - return 0; -# endif /* ACE_HAS_PHARLAP */ -# endif /* Winsock 2 && MSVC 5 or later */ - -#elif defined (__unix) || defined (__Lynx__) || defined (_AIX) - // COMMON (SVR4 and BSD) UNIX CODE - - size_t num_ifs; - - // Call specific routine as necessary. - ACE_HANDLE handle = get_handle(); - - if (handle == ACE_INVALID_HANDLE) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("ACE::get_ip_interfaces:open")), - -1); - if (ACE::count_interfaces (handle, num_ifs)) - { - ACE_OS::close (handle); - return -1; - } - - // ioctl likes to have an extra ifreq structure to mark the end of - // what it returned, so increase the num_ifs by one. - ++num_ifs; - - struct ifreq *ifs = 0; - ACE_NEW_RETURN (ifs, - struct ifreq[num_ifs], - -1); - ACE_OS::memset (ifs, 0, num_ifs * sizeof (struct ifreq)); - - ACE_Auto_Array_Ptr<struct ifreq> p_ifs (ifs); - - if (p_ifs.get() == 0) - { - ACE_OS::close (handle); - errno = ENOMEM; - return -1; - } - - struct ifconf ifcfg; - ACE_OS::memset (&ifcfg, 0, sizeof (struct ifconf)); - ifcfg.ifc_req = p_ifs.get (); - ifcfg.ifc_len = num_ifs * sizeof (struct ifreq); - -#if defined (AIX) - int cmd = CSIOCGIFCONF; -#else - int cmd = SIOCGIFCONF; -#endif /* AIX */ - if (ACE_OS::ioctl (handle, - cmd, - (caddr_t) &ifcfg) == -1) - { - ACE_OS::close (handle); - ACE_ERROR_RETURN ((LM_ERROR, - ACE_LIB_TEXT ("%p\n"), - ACE_LIB_TEXT ("is_address_local:") - ACE_LIB_TEXT ("ioctl - SIOCGIFCONF failed")), - -1); - } - - ACE_OS::close (handle); - - // Now create and initialize output array. - - ACE_NEW_RETURN (addrs, - ACE_INET_Addr[num_ifs], - -1); // caller must free - - struct ifreq *pcur = p_ifs.get (); - // Pull the address out of each INET interface. Not every interface - // is for IP, so be careful to count properly. When setting the - // INET_Addr, note that the 3rd arg (0) says to leave the byte order - // (already in net byte order from the interface structure) as is. - count = 0; - - for (size_t i = 0; - i < num_ifs; - i++) - { - if (pcur->ifr_addr.sa_family == AF_INET) - { -#if !defined(_UNICOS) - struct sockaddr_in *addr = - ACE_reinterpret_cast(sockaddr_in *, &pcur->ifr_addr); - - // Sometimes the kernel returns 0.0.0.0 as the interface - // address, skip those... - if (addr->sin_addr.s_addr != 0) - { - addrs[count].set ((u_short) 0, - addr->sin_addr.s_addr, - 0); - count++; - } -#else /* ! _UNICOS */ - // need to explicitly copy on the Cray, since the bitfields kinda - // screw things up here - struct sockaddr_in inAddr; - - inAddr.sin_len = pcur->ifr_addr.sa_len; - inAddr.sin_family = pcur->ifr_addr.sa_family; - memcpy((void *)&(inAddr.sin_addr), - (const void *)&(pcur->ifr_addr.sa_data[8]), - sizeof(struct in_addr)); - - if (inAddr.sin_addr.s_addr != 0) - { - addrs[count].set(&inAddr, sizeof(struct sockaddr_in)); - count++; - } -#endif /* ! _UNICOS */ - } - -#if !defined(CHORUS_4) - pcur++; -#else - if (pcur->ifr_addr.sa_len <= sizeof (struct sockaddr)) - { - pcur++; - } - else - { - pcur = (struct ifreq *) - (pcur->ifr_addr.sa_len + (caddr_t) &pcur->ifr_addr); - } -#endif - } - return 0; -#else - ACE_UNUSED_ARG (count); - ACE_UNUSED_ARG (addrs); - ACE_NOTSUP_RETURN (-1);; // no implementation -#endif /* ACE_WIN32 */ -} - char * ACE::strndup (const char *str, size_t n) { @@ -4637,37 +3237,6 @@ ACE::strend (const wchar_t *s) } #endif -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - -template class ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX>; -template class ACE_Malloc_T<ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX, ACE_Control_Block>; -template class ACE_Allocator_Adapter<ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX> >; - -// Explicitly instantiate these templates in the multithreaded case -// since some classes need them. -# if defined (ACE_HAS_THREADS) -template class ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex>; -template class ACE_Malloc_T<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex, ACE_Control_Block>; -template class ACE_Allocator_Adapter<ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex> >; -# endif /* ACE_HAS_THREADS */ - -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX> -#pragma instantiate ACE_Malloc_T<ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX, ACE_Control_Block> -#pragma instantiate ACE_Allocator_Adapter<ACE_Malloc<ACE_LOCAL_MEMORY_POOL,ACE_SYNCH_MUTEX> > - -// Explicitly instantiate these templates in the multithreaded case -// since some classes need them. -# if defined (ACE_HAS_THREADS) -# pragma instantiate ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex> -# pragma instantiate ACE_Malloc_T<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex, ACE_Control_Block> -# pragma instantiate ACE_Allocator_Adapter<ACE_Malloc<ACE_LOCAL_MEMORY_POOL, ACE_Null_Mutex> > -# endif /* ACE_HAS_THREADS */ - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - - #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) && (defined (__unix) || defined (__Lynx__) || defined (_AIX)) template class ACE_Auto_Array_Ptr<struct ifreq>; template class ACE_Auto_Basic_Array_Ptr<struct ifreq>; |