Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / OS_NS_arpa_inet.cpp
blob8b20b1bbfaf3f5b45bfa0a7ec1c60d8e0c5eff72
1 // -*- C++ -*-
2 #include "ace/OS_NS_arpa_inet.h"
4 #if !defined (ACE_HAS_INLINED_OSCALLS)
5 # include "ace/OS_NS_arpa_inet.inl"
6 #endif /* ACE_HAS_INLINED_OSCALLS */
8 #include "ace/Basic_Types.h"
10 #include <cstdlib>
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 int
15 ACE_OS::inet_aton (const char *host_name, struct in_addr *addr)
17 #if defined (ACE_LACKS_INET_ATON)
18 # if defined (ACE_WIN32)
19 // Windows Server 2003 changed the behavior of a zero-length input
20 // string to inet_addr(). It used to return 0 (INADDR_ANY) but now
21 // returns -1 (INADDR_NONE). It will return INADDR_ANY for a 1-space
22 // string, though, as do previous versions of Windows.
23 if (host_name == 0 || host_name[0] == '\0')
24 host_name = " ";
25 # endif /* ACE_WIN32 */
27 # if defined (ACE_LACKS_INET_ADDR)
28 if (!host_name)
29 return 0;
30 ACE_UINT32 ip = 0;
31 int part = 0;
32 for (const char *dot; *host_name; host_name = *dot ? dot + 1 : dot, ++part)
34 if (part > 3)
35 return 0;
36 dot = ACE_OS::strchr (host_name, '.');
37 if (!dot)
38 dot = host_name + ACE_OS::strlen (host_name);
39 char *last;
40 const unsigned long n = std::strtoul (host_name, &last, 0);
41 if (last != dot)
42 return 0;
43 if (!*dot)
44 switch (part)
46 case 0:
47 # if ACE_SIZEOF_LONG > 4
48 if (n > 0xffffffff)
49 return 0;
50 # endif
51 ip = static_cast<ACE_UINT32> (n);
52 continue;
53 case 1:
54 if (n > 0xffffff)
55 return 0;
56 ip <<= 24;
57 ip |= n;
58 continue;
59 case 2:
60 if (n > 0xffff)
61 return 0;
62 ip <<= 16;
63 ip |= n;
64 continue;
66 if (n > 0xff)
67 return 0;
68 ip <<= 8;
69 ip |= n;
71 addr->s_addr = ACE_HTONL (ip);
72 return 1;
73 # else
74 unsigned long ip_addr = ACE_OS::inet_addr (host_name);
76 if (ip_addr == INADDR_NONE
77 // Broadcast addresses are weird...
78 && ACE_OS::strcmp (host_name, "255.255.255.255") != 0)
79 return 0;
80 else if (addr == 0)
81 return 0;
82 else
84 addr->s_addr = ip_addr; // Network byte ordered
85 return 1;
87 # endif // ACE_LACKS_INET_ADDR
88 #elif defined (ACE_VXWORKS) && (ACE_VXWORKS < 0x700)
89 // inet_aton() returns OK (0) on success and ERROR (-1) on failure.
90 // Must reset errno first. Refer to WindRiver SPR# 34949, SPR# 36026
91 ::errnoSet(0);
92 int result = ERROR;
93 ACE_OSCALL (::inet_aton (const_cast <char*>(host_name), addr), int, result);
94 return (result == ERROR) ? 0 : 1;
95 #else
96 // inet_aton() returns 0 upon failure, not -1 since -1 is a valid
97 // address (255.255.255.255).
98 return ::inet_aton (host_name, addr);
99 #endif /* ACE_LACKS_INET_ATON */
102 ACE_END_VERSIONED_NAMESPACE_DECL