OS_NS_arpa_inet.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // OS_NS_arpa_inet.inl,v 1.8 2006/05/16 13:01:02 jwillemsen Exp
00003 
00004 #include "ace/OS_NS_string.h"
00005 #include "ace/OS_NS_errno.h"
00006 #include "ace/OS_NS_stdio.h"
00007 
00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 ACE_INLINE unsigned long
00011 ACE_OS::inet_addr (const char *name)
00012 {
00013   ACE_OS_TRACE ("ACE_OS::inet_addr");
00014 #if defined (ACE_HAS_NONCONST_GETBY)
00015   return ::inet_addr (const_cast <char*> (name));
00016 #else
00017   return ::inet_addr (name);
00018 #endif /* ACE_HAS_NONCONST_GETBY */
00019 }
00020 
00021 ACE_INLINE char *
00022 ACE_OS::inet_ntoa (const struct in_addr addr)
00023 {
00024   ACE_OS_TRACE ("ACE_OS::inet_ntoa");
00025   ACE_OSCALL_RETURN (::inet_ntoa (addr),
00026                      char *,
00027                      0);
00028 }
00029 
00030 ACE_INLINE const char *
00031 ACE_OS::inet_ntop (int family, const void *addrptr, char *strptr, size_t len)
00032 {
00033   ACE_OS_TRACE ("ACE_OS::inet_ntop");
00034 
00035 #if defined (ACE_HAS_IPV6) && !defined (ACE_WIN32)
00036   ACE_OSCALL_RETURN (::inet_ntop (family, addrptr, strptr, len), const char *, 0);
00037 #else
00038   const u_char *p = reinterpret_cast<const u_char *> (addrptr);
00039 
00040   if (family == AF_INET)
00041     {
00042       char temp[INET_ADDRSTRLEN];
00043 
00044       // Stevens uses snprintf() in his implementation but snprintf()
00045       // doesn't appear to be very portable.  For now, hope that using
00046       // sprintf() will not cause any string/memory overrun problems.
00047       ACE_OS::sprintf (temp,
00048                        "%d.%d.%d.%d",
00049                        p[0], p[1], p[2], p[3]);
00050 
00051       if (ACE_OS::strlen (temp) >= len)
00052         {
00053           errno = ENOSPC;
00054           return 0; // Failure
00055         }
00056 
00057       ACE_OS::strcpy (strptr, temp);
00058       return strptr;
00059     }
00060 
00061   ACE_NOTSUP_RETURN(0);
00062 #endif /* ACE_HAS_IPV6 */
00063 }
00064 ACE_INLINE int
00065 ACE_OS::inet_pton (int family, const char *strptr, void *addrptr)
00066 {
00067   ACE_OS_TRACE ("ACE_OS::inet_pton");
00068 
00069 #if defined (ACE_HAS_IPV6) && !defined (ACE_WIN32)
00070   ACE_OSCALL_RETURN (::inet_pton (family, strptr, addrptr), int, -1);
00071 #else
00072   if (family == AF_INET)
00073     {
00074       struct in_addr in_val;
00075 
00076       if (ACE_OS::inet_aton (strptr, &in_val))
00077         {
00078           ACE_OS::memcpy (addrptr, &in_val, sizeof (struct in_addr));
00079           return 1; // Success
00080         }
00081 
00082       return 0; // Input is not a valid presentation format
00083     }
00084 
00085   ACE_NOTSUP_RETURN(-1);
00086 #endif  /* ACE_HAS_IPV6 */
00087 }
00088 
00089 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:57 2006 for ACE by doxygen 1.3.6