首页 > 解决方案 > gethostbyname() 函数的源码实现在哪里?

问题描述

从 glibc 树中,我只能看到文件gethstbynm.cglibc-2.32/inet/gethstbynm.c),但没有实现代码:

#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>

我想找到https://www.amazon.com/Unix-Network-Programming-Sockets-Networking/dp/0131411551建议的实现:

static struct hostent host ;
/* result stored here */
struct hostent *
gethostbyname (const char *hostname)
{
return (gethostbyname2 (hostname, family));
}

什么文件存储实现?

编辑: 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

标签: cimplementationglibcgethostbyname

解决方案


在 linux上是在( see heregethostbyname() )中声明的,通过宏 in (see here) 进行伪定义glibc/resolv/netdb.h最后在( see here ) 中定义。inet/gethstbynm.cnss/getXXbyYY.c


推荐阅读