From glibc tree, I can see only file gethstbynm.c (glibc-2.32/inet/gethstbynm.c), but there is no implementation code:
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define LOOKUP_TYPE struct hostent
#define FUNCTION_NAME gethostbyname
#define DATABASE_NAME hosts
#define ADD_PARAMS const char *name
#define ADD_VARIABLES name
#define BUFLEN 1024
#define NEED_H_ERRNO 1
#define HANDLE_DIGITS_DOTS 1
#include <nss/getXXbyYY.c>
I would like to find the implementation as https://www.amazon.com/Unix-Network-Programming-Sockets-Networking/dp/0131411551 suggest:
static struct hostent host ;
/* result stored here */
struct hostent *
gethostbyname (const char *hostname)
{
return (gethostbyname2 (hostname, family));
}
What file stores the implementation?
EDIT: uname -a:
Linux 5.8.0-40-generic #45-Ubuntu SMP Fri Jan 15 11:05:36 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
On linux
gethostbyname()is declared inglibc/resolv/netdb.h(see here), pseudo defined via macros ininet/gethstbynm.c(see here), and finally defined innss/getXXbyYY.c(see here).