a problem about a function __gethostbyname_r in the source file of gethostbyname

Viewed 56

I'm a new programer.When I try to read the source file of gethostbyname() in getXXbyYY.c,glibc , I found a function about macro.

INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, &resbuf, buffer,buffer_size, &result H_ERRNO_VAR)

It can be resolved by following macros to be __gethostbyname_r().

#define REENTRANT_NAME APPEND_R (FUNCTION_NAME)
#define APPEND_R(name) APPEND_R1 (name)
#define APPEND_R1(name) name##_r
#define INTERNAL(name) INTERNAL1 (name)
#define INTERNAL1(name) __##name 

Then I try to find the implementation of __gethostbyname_r(), but I just found the prototype in netdb.h.

So, I want to know where is the implementation of __gethostbyname_r() and what will it do ?

1 Answers

With libc6-dbg package installed:

gdb /lib/x86_64-linux-gnu/libc.so.6

(gdb) info func __gethostbyname_r
All functions matching regular expression "__gethostbyname_r":

File ../nss/getXXbyYY_r.c:
188:    int __gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);

This tells you that you should look in $GLIBC_SRC/nss/getXXbyYY_r.c file, around line 188.

Related