00001
00002
00003
00004
00005 #include "ace/OS_NS_macros.h"
00006 #include "ace/OS_NS_string.h"
00007 #include "ace/OS_NS_errno.h"
00008
00009 #if defined (ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
00010 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00011 # define ACE_NETDBCALL_RETURN(OP,TYPE,FAILVALUE,TARGET,SIZE) \
00012 do \
00013 { \
00014 if (ACE_OS::netdb_acquire ()) \
00015 return FAILVALUE; \
00016 else \
00017 { \
00018 TYPE ace_result_; \
00019 ACE_OSCALL (OP, TYPE, FAILVALUE, ace_result_); \
00020 if (ace_result_ != FAILVALUE) \
00021 ACE_OS::memcpy (TARGET, \
00022 ace_result_, \
00023 SIZE < sizeof (TYPE) ? SIZE : sizeof (TYPE)); \
00024 ACE_OS::netdb_release (); \
00025 return ace_result_; \
00026 } \
00027 } while(0)
00028 # else
00029 # define ACE_NETDBCALL_RETURN(OP,TYPE,FAILVALUE,TARGET,SIZE) \
00030 do \
00031 { \
00032 TYPE ace_result_; \
00033 ACE_OSCALL(OP,TYPE,FAILVALUE,ace_result_); \
00034 if (ace_result_ != FAILVALUE) \
00035 ACE_OS::memcpy (TARGET, \
00036 ace_result_, \
00037 SIZE < sizeof (TYPE) ? SIZE : sizeof (TYPE)); \
00038 return ace_result_; \
00039 } while(0)
00040 # endif
00041 #endif
00042
00043 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00044
00045 #if !(defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYADDR))
00046
00047 ACE_INLINE struct hostent *
00048 ACE_OS::gethostbyaddr (const char *addr, int length, int type)
00049 {
00050 ACE_OS_TRACE ("ACE_OS::gethostbyaddr");
00051 # if defined (ACE_LACKS_GETHOSTBYADDR)
00052 ACE_UNUSED_ARG (addr);
00053 ACE_UNUSED_ARG (length);
00054 ACE_UNUSED_ARG (type);
00055 ACE_NOTSUP_RETURN (0);
00056 # elif defined (ACE_HAS_NONCONST_GETBY)
00057 ACE_SOCKCALL_RETURN (::gethostbyaddr (const_cast<char *> (addr),
00058 (ACE_SOCKET_LEN) length,
00059 type),
00060 struct hostent *,
00061 0);
00062 # else
00063 ACE_SOCKCALL_RETURN (::gethostbyaddr (addr,
00064 (ACE_SOCKET_LEN) length,
00065 type),
00066 struct hostent *,
00067 0);
00068 # endif
00069 }
00070
00071 #endif
00072
00073 #if !(defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYADDR))
00074
00075 ACE_INLINE struct hostent *
00076 ACE_OS::gethostbyaddr_r (const char *addr,
00077 int length,
00078 int type,
00079 struct hostent *result,
00080 ACE_HOSTENT_DATA buffer,
00081 int *h_errnop)
00082 {
00083 ACE_OS_TRACE ("ACE_OS::gethostbyaddr_r");
00084 # if defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
00085 # if defined (AIX) || defined (DIGITAL_UNIX)
00086 ACE_OS::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
00087
00088 if (::gethostbyaddr_r ((char *) addr, length, type, result,
00089 (struct hostent_data *) buffer)== 0)
00090 return result;
00091 else
00092 {
00093 *h_errnop = h_errno;
00094 return (struct hostent *) 0;
00095 }
00096 # elif defined (__GLIBC__)
00097
00098 ACE_OS::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
00099
00100 if (::gethostbyaddr_r ((char *) addr,
00101 length,
00102 type,
00103 result,
00104 buffer,
00105 sizeof (ACE_HOSTENT_DATA),
00106 &result,
00107 h_errnop) == 0)
00108 return result;
00109 else
00110 return (struct hostent *) 0;
00111 # else
00112 # if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
00113 ACE_UNUSED_ARG (result);
00114 ACE_UNUSED_ARG (h_errnop);
00115 ACE_NETDBCALL_RETURN (::gethostbyaddr (addr, (ACE_SOCKET_LEN) length, type),
00116 struct hostent *, 0,
00117 buffer, sizeof (ACE_HOSTENT_DATA));
00118 # else
00119 ACE_SOCKCALL_RETURN (::gethostbyaddr_r (addr, length, type, result,
00120 buffer, sizeof (ACE_HOSTENT_DATA),
00121 h_errnop),
00122 struct hostent *, 0);
00123 # endif
00124 # endif
00125 # elif defined (ACE_HAS_NONCONST_GETBY)
00126 ACE_UNUSED_ARG (result);
00127 ACE_UNUSED_ARG (buffer);
00128 ACE_UNUSED_ARG (h_errnop);
00129 ACE_SOCKCALL_RETURN (::gethostbyaddr (const_cast<char *> (addr),
00130 (ACE_SOCKET_LEN) length,
00131 type),
00132 struct hostent *,
00133 0);
00134 # else
00135 ACE_UNUSED_ARG (h_errnop);
00136 ACE_UNUSED_ARG (buffer);
00137 ACE_UNUSED_ARG (result);
00138
00139 ACE_SOCKCALL_RETURN (::gethostbyaddr (addr,
00140 (ACE_SOCKET_LEN) length,
00141 type),
00142 struct hostent *,
00143 0);
00144 # endif
00145 }
00146
00147 #endif
00148
00149 #if !(defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYNAME))
00150
00151 ACE_INLINE struct hostent *
00152 ACE_OS::gethostbyname (const char *name)
00153 {
00154 ACE_OS_TRACE ("ACE_OS::gethostbyname");
00155 # if defined (ACE_LACKS_GETHOSTBYNAME)
00156 ACE_UNUSED_ARG (name);
00157 ACE_NOTSUP_RETURN (0);
00158 # elif defined (ACE_HAS_NONCONST_GETBY)
00159 ACE_SOCKCALL_RETURN (::gethostbyname (const_cast<char *> (name)),
00160 struct hostent *,
00161 0);
00162 # else
00163 ACE_SOCKCALL_RETURN (::gethostbyname (name),
00164 struct hostent *,
00165 0);
00166 # endif
00167 }
00168
00169 #endif
00170
00171 #if !(defined (ACE_VXWORKS) && defined (ACE_LACKS_GETHOSTBYNAME))
00172
00173 ACE_INLINE struct hostent *
00174 ACE_OS::gethostbyname_r (const char *name,
00175 struct hostent *result,
00176 ACE_HOSTENT_DATA buffer,
00177 int *h_errnop)
00178 {
00179 ACE_OS_TRACE ("ACE_OS::gethostbyname_r");
00180 #if defined (ACE_LACKS_GETHOSTBYNAME)
00181 ACE_UNUSED_ARG (name);
00182 ACE_UNUSED_ARG (result);
00183 ACE_UNUSED_ARG (buffer);
00184 ACE_UNUSED_ARG (h_errnop);
00185 ACE_NOTSUP_RETURN (0);
00186 # elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
00187 # if defined (DIGITAL_UNIX) || \
00188 (defined (ACE_AIX_MINOR_VERS) && (ACE_AIX_MINOR_VERS > 2))
00189 ACE_UNUSED_ARG (result);
00190 ACE_UNUSED_ARG (buffer);
00191 ACE_UNUSED_ARG (h_errnop);
00192
00193
00194
00195 ACE_SOCKCALL_RETURN (::gethostbyname (name), struct hostent *, 0);
00196 # elif defined (AIX)
00197 ACE_OS::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
00198
00199 if (::gethostbyname_r (name, result, (struct hostent_data *) buffer) == 0)
00200 return result;
00201 else
00202 {
00203 *h_errnop = h_errno;
00204 return (struct hostent *) 0;
00205 }
00206 # elif defined (__GLIBC__)
00207
00208 ACE_OS::memset (buffer, 0, sizeof (ACE_HOSTENT_DATA));
00209
00210 if (::gethostbyname_r (name,
00211 result,
00212 buffer,
00213 sizeof (ACE_HOSTENT_DATA),
00214 &result,
00215 h_errnop) == 0)
00216 return result;
00217 else
00218 return (struct hostent *) 0;
00219 # else
00220 # if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
00221 ACE_UNUSED_ARG (result);
00222 ACE_UNUSED_ARG (h_errnop);
00223 ACE_NETDBCALL_RETURN (::gethostbyname (name),
00224 struct hostent *, 0,
00225 buffer, sizeof (ACE_HOSTENT_DATA));
00226 # else
00227 ACE_SOCKCALL_RETURN (::gethostbyname_r (name, result, buffer,
00228 sizeof (ACE_HOSTENT_DATA),
00229 h_errnop),
00230 struct hostent *,
00231 0);
00232 # endif
00233 # endif
00234 # elif defined (ACE_HAS_NONCONST_GETBY)
00235 ACE_UNUSED_ARG (result);
00236 ACE_UNUSED_ARG (buffer);
00237 ACE_UNUSED_ARG (h_errnop);
00238 ACE_SOCKCALL_RETURN (::gethostbyname (const_cast<char *> (name)),
00239 struct hostent *,
00240 0);
00241 # else
00242 ACE_UNUSED_ARG (result);
00243 ACE_UNUSED_ARG (buffer);
00244 ACE_UNUSED_ARG (h_errnop);
00245
00246 ACE_SOCKCALL_RETURN (::gethostbyname (name),
00247 struct hostent *,
00248 0);
00249 # endif
00250 }
00251
00252 #endif
00253
00254 ACE_INLINE struct hostent *
00255 ACE_OS::getipnodebyaddr (const void *src, size_t len, int family)
00256 {
00257 #if defined (ACE_HAS_IPV6) && !defined (ACE_WIN32)
00258 # if defined (ACE_LACKS_GETIPNODEBYADDR)
00259 ACE_UNUSED_ARG (src);
00260 ACE_UNUSED_ARG (len);
00261 ACE_UNUSED_ARG (family);
00262 ACE_NOTSUP_RETURN (0);
00263 # else
00264 struct hostent *hptr;
00265 int errnum;
00266 if ((hptr = ::getipnodebyaddr (src, len, family, &errnum)) == 0)
00267 {
00268 errno = errnum;
00269 }
00270 return hptr;
00271 # endif
00272 #else
00273
00274 if (family == AF_INET)
00275 return ACE_OS::gethostbyaddr (static_cast<const char *> (src),
00276 static_cast<int> (len),
00277 family);
00278
00279 ACE_NOTSUP_RETURN (0);
00280 # endif
00281 }
00282
00283 ACE_INLINE struct hostent *
00284 ACE_OS::getipnodebyname (const char *name, int family, int flags)
00285 {
00286 ACE_OS_TRACE ("ACE_OS::getipnodebyname");
00287 # if defined (ACE_HAS_IPV6) && !defined (ACE_WIN32)
00288 # if defined (ACE_LACKS_GETIPNODEBYNAME)
00289 ACE_UNUSED_ARG (flags);
00290 # if defined (ACE_HAS_NONCONST_GETBY)
00291 ACE_SOCKCALL_RETURN (::gethostbyname2 (const_cast<char *> (name),
00292 family),
00293 struct hostent *, 0);
00294 # else
00295 ACE_SOCKCALL_RETURN (::gethostbyname2 (name, family),
00296 struct hostent *, 0);
00297 # endif
00298 # else
00299 struct hostent *hptr;
00300 int errnum;
00301 if ((hptr = ::getipnodebyname (name, family, flags, &errnum)) == 0)
00302 {
00303 errno = errnum;
00304 }
00305 return hptr;
00306 # endif
00307 # else
00308
00309 ACE_UNUSED_ARG (flags);
00310 if (family == AF_INET)
00311 return ACE_OS::gethostbyname (name);
00312
00313 ACE_NOTSUP_RETURN (0);
00314 # endif
00315 }
00316
00317 ACE_INLINE struct protoent *
00318 ACE_OS::getprotobyname (const char *name)
00319 {
00320 #if defined (ACE_LACKS_GETPROTOBYNAME)
00321 ACE_UNUSED_ARG (name);
00322 ACE_NOTSUP_RETURN (0);
00323 #elif defined (ACE_HAS_NONCONST_GETBY)
00324 ACE_SOCKCALL_RETURN (::getprotobyname (const_cast<char *> (name)),
00325 struct protoent *,
00326 0);
00327 #else
00328 ACE_SOCKCALL_RETURN (::getprotobyname (name),
00329 struct protoent *,
00330 0);
00331 #endif
00332 }
00333
00334 ACE_INLINE struct protoent *
00335 ACE_OS::getprotobyname_r (const char *name,
00336 struct protoent *result,
00337 ACE_PROTOENT_DATA buffer)
00338 {
00339 #if defined (ACE_LACKS_GETPROTOBYNAME)
00340 ACE_UNUSED_ARG (name);
00341 ACE_UNUSED_ARG (result);
00342 ACE_UNUSED_ARG (buffer);
00343 ACE_NOTSUP_RETURN (0);
00344 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
00345 # if defined (AIX) || defined (DIGITAL_UNIX)
00346 if (::getprotobyname_r (name, result, (struct protoent_data *) buffer) == 0)
00347 return result;
00348 else
00349 return 0;
00350 # elif defined (__GLIBC__)
00351
00352 if (::getprotobyname_r (name,
00353 result,
00354 buffer,
00355 sizeof (ACE_PROTOENT_DATA),
00356 &result) == 0)
00357 return result;
00358 else
00359 return 0;
00360 # else
00361 # if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
00362 ACE_UNUSED_ARG (result);
00363 ACE_NETDBCALL_RETURN (::getprotobyname (name),
00364 struct protoent *, 0,
00365 buffer, sizeof (ACE_PROTOENT_DATA));
00366 # else
00367 ACE_SOCKCALL_RETURN (::getprotobyname_r (name,
00368 result,
00369 buffer,
00370 sizeof (ACE_PROTOENT_DATA)),
00371 struct protoent *, 0);
00372 # endif
00373 # endif
00374 #elif defined (ACE_HAS_NONCONST_GETBY)
00375 ACE_UNUSED_ARG (result);
00376 ACE_UNUSED_ARG (buffer);
00377 ACE_SOCKCALL_RETURN (::getprotobyname (const_cast<char *> (name)),
00378 struct protoent *, 0);
00379 #else
00380 ACE_UNUSED_ARG (buffer);
00381 ACE_UNUSED_ARG (result);
00382
00383 ACE_SOCKCALL_RETURN (::getprotobyname (name),
00384 struct protoent *,
00385 0);
00386 #endif
00387 }
00388
00389 ACE_INLINE struct protoent *
00390 ACE_OS::getprotobynumber (int proto)
00391 {
00392 #if defined (ACE_LACKS_GETPROTOBYNUMBER)
00393 ACE_UNUSED_ARG (proto);
00394 ACE_NOTSUP_RETURN (0);
00395 #else
00396 ACE_SOCKCALL_RETURN (::getprotobynumber (proto),
00397 struct protoent *, 0);
00398 #endif
00399 }
00400
00401 ACE_INLINE struct protoent *
00402 ACE_OS::getprotobynumber_r (int proto,
00403 struct protoent *result,
00404 ACE_PROTOENT_DATA buffer)
00405 {
00406 #if defined (ACE_LACKS_GETPROTOBYNUMBER)
00407 ACE_UNUSED_ARG (proto);
00408 ACE_UNUSED_ARG (result);
00409 ACE_UNUSED_ARG (buffer);
00410 ACE_NOTSUP_RETURN (0);
00411 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
00412 # if defined (AIX) || defined (DIGITAL_UNIX)
00413 if (::getprotobynumber_r (proto, result, (struct protoent_data *) buffer) == 0)
00414 return result;
00415 else
00416 return 0;
00417 # elif defined (__GLIBC__)
00418
00419 if (::getprotobynumber_r (proto,
00420 result,
00421 buffer,
00422 sizeof (ACE_PROTOENT_DATA),
00423 &result) == 0)
00424 return result;
00425 else
00426 return 0;
00427 # else
00428 # if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
00429 ACE_UNUSED_ARG (result);
00430 ACE_NETDBCALL_RETURN (::getprotobynumber (proto),
00431 struct protoent *, 0,
00432 buffer, sizeof (ACE_PROTOENT_DATA));
00433 # else
00434 ACE_SOCKCALL_RETURN (::getprotobynumber_r (proto, result, buffer, sizeof (ACE_PROTOENT_DATA)),
00435 struct protoent *, 0);
00436 # endif
00437 # endif
00438 #else
00439 ACE_UNUSED_ARG (buffer);
00440 ACE_UNUSED_ARG (result);
00441
00442 ACE_SOCKCALL_RETURN (::getprotobynumber (proto),
00443 struct protoent *, 0);
00444 #endif
00445 }
00446
00447 ACE_INLINE struct servent *
00448 ACE_OS::getservbyname (const char *svc, const char *proto)
00449 {
00450 ACE_OS_TRACE ("ACE_OS::getservbyname");
00451 #if defined (ACE_LACKS_GETSERVBYNAME)
00452 ACE_UNUSED_ARG (svc);
00453 ACE_UNUSED_ARG (proto);
00454 ACE_NOTSUP_RETURN (0);
00455 #elif defined (ACE_HAS_NONCONST_GETBY)
00456 ACE_SOCKCALL_RETURN (::getservbyname (const_cast<char *> (svc),
00457 const_cast<char *> (proto)),
00458 struct servent *,
00459 0);
00460 #else
00461 ACE_SOCKCALL_RETURN (::getservbyname (svc,
00462 proto),
00463 struct servent *,
00464 0);
00465 #endif
00466 }
00467
00468 ACE_INLINE struct servent *
00469 ACE_OS::getservbyname_r (const char *svc,
00470 const char *proto,
00471 struct servent *result,
00472 ACE_SERVENT_DATA buf)
00473 {
00474 ACE_OS_TRACE ("ACE_OS::getservbyname_r");
00475 #if defined (ACE_LACKS_GETSERVBYNAME)
00476 ACE_UNUSED_ARG (svc);
00477 ACE_UNUSED_ARG (proto);
00478 ACE_UNUSED_ARG (result);
00479 ACE_UNUSED_ARG (buf);
00480 ACE_NOTSUP_RETURN (0);
00481 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (UNIXWARE)
00482 # if defined (AIX) || defined (DIGITAL_UNIX)
00483 ACE_OS::memset (buf, 0, sizeof (ACE_SERVENT_DATA));
00484
00485 if (::getservbyname_r (svc, proto, result, (struct servent_data *) buf) == 0)
00486 return result;
00487 else
00488 return (struct servent *) 0;
00489 # elif defined (__GLIBC__)
00490
00491 ACE_OS::memset (buf, 0, sizeof (ACE_SERVENT_DATA));
00492
00493 if (::getservbyname_r (svc,
00494 proto,
00495 result,
00496 buf,
00497 sizeof (ACE_SERVENT_DATA),
00498 &result) == 0)
00499 return result;
00500 else
00501 return (struct servent *) 0;
00502 # else
00503 # if defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS)
00504 ACE_UNUSED_ARG (result);
00505 ACE_NETDBCALL_RETURN (::getservbyname (svc, proto),
00506 struct servent *, 0,
00507 buf, sizeof (ACE_SERVENT_DATA));
00508 # else
00509 ACE_SOCKCALL_RETURN (::getservbyname_r (svc, proto, result, buf,
00510 sizeof (ACE_SERVENT_DATA)),
00511 struct servent *, 0);
00512 # endif
00513 # endif
00514 #elif defined (ACE_HAS_NONCONST_GETBY)
00515 ACE_UNUSED_ARG (buf);
00516 ACE_UNUSED_ARG (result);
00517 ACE_SOCKCALL_RETURN (::getservbyname (const_cast<char *> (svc),
00518 const_cast<char *> (proto)),
00519 struct servent *,
00520 0);
00521 #else
00522 ACE_UNUSED_ARG (buf);
00523 ACE_UNUSED_ARG (result);
00524
00525 ACE_SOCKCALL_RETURN (::getservbyname (svc,
00526 proto),
00527 struct servent *,
00528 0);
00529 #endif
00530 }
00531
00532 ACE_END_VERSIONED_NAMESPACE_DECL