/*
- * Copyright (C) 2001,2002,2003,2004,2005 by the Massachusetts Institute of Technology,
+ * Copyright (C) 2001,2002,2003,2004,2005,2006 by the Massachusetts Institute of Technology,
* Cambridge, MA, USA. All Rights Reserved.
*
* This software is being provided to you, the LICENSEE, by the
either getaddrinfo or one of these two flavors of
gethostbyname_r? */
#if !defined(HAVE_GETHOSTBYNAME_R) || defined(THREADSAFE_GETHOSTBYNAME)
-#define GET_HOST_BY_NAME(NAME, HP, ERR) \
- { (HP) = gethostbyname (NAME); (ERR) = h_errno; }
-#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR) \
- { (HP) = gethostbyaddr ((ADDR), (ADDRLEN), (FAMILY)); (ERR) = h_errno; }
+typedef struct hostent *GET_HOST_TMP;
+#define GET_HOST_BY_NAME(NAME, HP, ERR, TMP) \
+ { TMP = gethostbyname (NAME); (ERR) = h_errno; (HP) = TMP; }
+#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR, TMP) \
+ { TMP = gethostbyaddr ((ADDR), (ADDRLEN), (FAMILY)); (ERR) = h_errno; (HP) = TMP; }
#else
#ifdef _AIX /* XXX should have a feature test! */
-#define GET_HOST_BY_NAME(NAME, HP, ERR) \
- { \
- struct hostent my_h_ent; \
- struct hostent_data my_h_ent_data; \
- (HP) = (gethostbyname_r((NAME), &my_h_ent, &my_h_ent_data) \
- ? 0 \
- : &my_h_ent); \
- (ERR) = h_errno; \
+typedef struct {
+ struct hostent ent;
+ struct hostent_data data;
+} GET_HOST_TMP;
+#define GET_HOST_BY_NAME(NAME, HP, ERR, TMP) \
+ { \
+ (HP) = (gethostbyname_r((NAME), &TMP.ent, &TMP.data) \
+ ? 0 \
+ : &my_h_ent); \
+ (ERR) = h_errno; \
}
/*
#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR) \
*/
#else
#ifdef GETHOSTBYNAME_R_RETURNS_INT
-#define GET_HOST_BY_NAME(NAME, HP, ERR) \
+typedef struct {
+ struct hostent ent, *hp;
+ int err;
+ char buf[8192];
+} GET_HOST_TMP;
+#define GET_HOST_BY_NAME(NAME, HP, ERR, TMP) \
{ \
- struct hostent my_h_ent, *my_hp; \
- int my_h_err; \
- char my_h_buf[8192]; \
- (HP) = (gethostbyname_r((NAME), &my_h_ent, \
- my_h_buf, sizeof (my_h_buf), &my_hp, \
- &my_h_err) \
+ (HP) = (gethostbyname_r((NAME), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf), &TMP.hp, \
+ &TMP.err) \
? 0 \
- : &my_h_ent); \
- (ERR) = my_h_err; \
+ : &TMP.ent); \
+ (ERR) = TMP.err; \
}
-#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR) \
+#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR, TMP) \
{ \
- struct hostent my_h_ent, *my_hp; \
- int my_h_err; \
- char my_h_buf[8192]; \
- (HP) = (gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &my_h_ent, \
- my_h_buf, sizeof (my_h_buf), &my_hp, \
- &my_h_err) \
+ (HP) = (gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf), &TMP.hp, \
+ &TMP.err) \
? 0 \
- : &my_h_ent); \
- (ERR) = my_h_err; \
+ : &TMP.ent); \
+ (ERR) = TMP.err; \
}
#else
-#define GET_HOST_BY_NAME(NAME, HP, ERR) \
+typedef struct {
+ struct hostent ent;
+ int err;
+ char buf[8192];
+} GET_HOST_TMP;
+#define GET_HOST_BY_NAME(NAME, HP, ERR, TMP) \
{ \
- struct hostent my_h_ent; \
- int my_h_err; \
- char my_h_buf[8192]; \
- (HP) = gethostbyname_r((NAME), &my_h_ent, \
- my_h_buf, sizeof (my_h_buf), &my_h_err); \
- (ERR) = my_h_err; \
+ (HP) = gethostbyname_r((NAME), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf), &TMP.err); \
+ (ERR) = TMP.err; \
}
-#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR) \
+#define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR, TMP) \
{ \
- struct hostent my_h_ent; \
- int my_h_err; \
- char my_h_buf[8192]; \
- (HP) = gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &my_h_ent, \
- my_h_buf, sizeof (my_h_buf), &my_h_err); \
- (ERR) = my_h_err; \
+ (HP) = gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf), &TMP.err); \
+ (ERR) = TMP.err; \
}
#endif /* returns int? */
#endif /* _AIX */
/* Now do the same for getservby* functions. */
#ifndef HAVE_GETSERVBYNAME_R
-#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR) \
- ((SP) = getservbyname (NAME, PROTO), (ERR) = (SP) ? 0 : -1)
-#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR) \
- ((SP) = getservbyport (PORT, PROTO), (ERR) = (SP) ? 0 : -1)
+typedef struct servent *GET_SERV_TMP;
+#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR, TMP) \
+ (TMP = getservbyname (NAME, PROTO), (SP) = TMP, (ERR) = (SP) ? 0 : -1)
+#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR, TMP) \
+ (TMP = getservbyport (PORT, PROTO), (SP) = TMP, (ERR) = (SP) ? 0 : -1)
#else
#ifdef GETSERVBYNAME_R_RETURNS_INT
-#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR) \
+typedef struct {
+ struct servent ent, *sp;
+ int err;
+ char buf[8192];
+} GET_SERV_TMP;
+#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR, TMP) \
{ \
- struct servent my_s_ent, *my_sp; \
- int my_s_err; \
- char my_s_buf[8192]; \
- (SP) = (getservbyname_r((NAME), (PROTO), &my_s_ent, \
- my_s_buf, sizeof (my_s_buf), &my_sp, \
- &my_s_err) \
+ struct servent *my_sp; \
+ (SP) = (getservbyname_r((NAME), (PROTO), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf), &my_sp, \
+ &TMP.err) \
? 0 \
- : &my_s_ent); \
- (ERR) = my_s_err; \
+ : &TMP.ent); \
+ (ERR) = TMP.err; \
}
-#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR) \
+#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR, TMP) \
{ \
- struct servent my_s_ent, *my_sp; \
- int my_s_err; \
- char my_s_buf[8192]; \
- (SP) = (getservbyport_r((PORT), (PROTO), &my_s_ent, \
- my_s_buf, sizeof (my_s_buf), &my_sp, \
- &my_s_err) \
+ struct servent *my_sp; \
+ (SP) = (getservbyport_r((PORT), (PROTO), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf), &my_sp, \
+ &TMP.err) \
? 0 \
- : &my_s_ent); \
- (ERR) = my_s_err; \
+ : &TMP.ent); \
+ (ERR) = TMP.err; \
}
#else
/* returns ptr -- IRIX? */
-#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR) \
+typedef struct {
+ struct servent ent;
+ char buf[8192];
+} GET_SERV_TMP;
+#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR, TMP) \
{ \
- struct servent my_s_ent; \
- char my_s_buf[8192]; \
- (SP) = getservbyname_r((NAME), (PROTO), &my_s_ent, \
- my_s_buf, sizeof (my_s_buf)); \
+ (SP) = getservbyname_r((NAME), (PROTO), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf)); \
(ERR) = (SP) == NULL; \
}
-#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR) \
+#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR, TMP) \
{ \
- struct servent my_s_ent, *my_sp; \
- char my_s_buf[8192]; \
- my_sp = getservbyport_r((PORT), (PROTO), &my_s_ent, \
- my_s_buf, sizeof (my_s_buf)); \
+ struct servent *my_sp; \
+ my_sp = getservbyport_r((PORT), (PROTO), &TMP.ent, \
+ TMP.buf, sizeof (TMP.buf)); \
(SP) = my_sp; \
(ERR) = my_sp == 0; \
(ERR) = (ERR); /* avoid "unused" warning */ \
struct hostent *hp;
int i, r;
int herr;
+ GET_HOST_TMP htmp;
- GET_HOST_BY_NAME (name, hp, herr);
+ GET_HOST_BY_NAME (name, hp, herr, htmp);
if (hp == 0)
return translate_h_errno (herr);
for (i = 0; hp->h_addr_list[i]; i++) {
} else {
struct servent *sp;
int try_dgram_too = 0, s_err;
+ GET_SERV_TMP stmp;
if (socktype == 0) {
try_dgram_too = 1;
}
try_service_lookup:
GET_SERV_BY_NAME(serv, socktype == SOCK_STREAM ? "tcp" : "udp",
- sp, s_err);
+ sp, s_err, stmp);
if (sp == 0) {
if (try_dgram_too) {
socktype = SOCK_DGRAM;
#endif
} else {
int herr;
+ GET_HOST_TMP htmp;
+
GET_HOST_BY_ADDR((const char *) &sinp->sin_addr,
sizeof (struct in_addr),
- sa->sa_family, hp, herr);
+ sa->sa_family, hp, herr, htmp);
if (hp == 0) {
if (herr == NO_ADDRESS && !(flags & NI_NAMEREQD)) /* ??? */
goto numeric_host;
strncpy (service, numbuf, slen);
} else {
int serr;
+ GET_SERV_TMP stmp;
+
GET_SERV_BY_PORT(sinp->sin_port,
(flags & NI_DGRAM) ? "udp" : "tcp",
- sp, serr);
+ sp, serr, stmp);
if (sp == 0)
goto numeric_service;
strncpy (service, sp->s_name, slen);
struct hostent *hp;
const char *name2 = 0;
int i, herr;
+ GET_HOST_TMP htmp;
/*
* Current versions of GET_HOST_BY_NAME will fail if the
* target hostname has IPv6 addresses only. Make sure it
* fails fairly cleanly.
*/
- GET_HOST_BY_NAME (name, hp, herr);
+ GET_HOST_BY_NAME (name, hp, herr, htmp);
if (hp == 0) {
/*
* This case probably means it's an IPv6-only name. If