(GET_HOST_BY_NAME, GET_HOST_BY_ADDR) [GETHOSTBYNAME_RETURNS_INT]: Test
authorKen Raeburn <raeburn@mit.edu>
Wed, 21 Jun 2006 00:28:21 +0000 (00:28 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 21 Jun 2006 00:28:21 +0000 (00:28 +0000)
the output hostent pointer as an additional way of checking for errors.
Original patch from Nalin Dahyabhai, needed some tweaking to fit in
current sources, especially as updated in ticket 3911.

ticket: 2759
tags: pullup

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18183 dc483132-0cff-0310-8789-dd5450dbe970

src/util/support/fake-addrinfo.c

index a622302b87cfdef7a22cdf2a81fd2c6ccb7ecd57..cdc2fdd04850cb7c2654fc0142338d565047cfc8 100644 (file)
@@ -200,11 +200,12 @@ typedef struct {
 } GET_HOST_TMP;
 #define GET_HOST_BY_NAME(NAME, HP, ERR, TMP) \
     {                                                                  \
-       struct hostent *my_hp;                                          \
-       int my_h_err;                                                   \
-       (HP) = (gethostbyname_r((NAME), &TMP.ent,                       \
-                               TMP.buf, sizeof (TMP.buf), &TMP.hp,     \
-                               &my_h_err)                              \
+       struct hostent *my_hp = NULL;                                   \
+       int my_h_err, my_ret;                                           \
+       my_ret = gethostbyname_r((NAME), &TMP.ent,                      \
+                                TMP.buf, sizeof (TMP.buf), &TMP.hp,    \
+                                &my_h_err);                            \
+       (HP) = (((my_ret != 0) || (TMP.hp != &TMP.ent))                 \
                ? 0                                                     \
                : &TMP.ent);                                            \
        (ERR) = my_h_err;                                               \
@@ -212,10 +213,11 @@ typedef struct {
 #define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR, TMP) \
     {                                                                  \
        struct hostent *my_hp;                                          \
-       int my_h_err;                                                   \
-       (HP) = (gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &TMP.ent,  \
-                               TMP.buf, sizeof (TMP.buf), &my_hp,      \
-                               &my_h_err)                              \
+       int my_h_err, my_ret;                                           \
+       my_ret = gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &TMP.ent, \
+                                TMP.buf, sizeof (TMP.buf), &my_hp,     \
+                                &my_h_err);                            \
+       (HP) = (((my_ret != 0) || (TMP.hp != &TMP.ent))                 \
                ? 0                                                     \
                : &TMP.ent);                                            \
        (ERR) = my_h_err;                                               \