【问题标题】:Where is the source code implementation of gethostbyname() function? [duplicate]gethostbyname() 函数的源码实现在哪里? [复制]
【发布时间】:2021-04-29 19:19:26
【问题描述】:

从 glibc 树中,我只能看到文件 gethstbynm.c (glibc-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));
}

什么文件存储了实现?

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

【问题讨论】:

  • 查看编辑......

标签: c implementation glibc gethostbyname


【解决方案1】:

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

【讨论】:

  • 虽然应该指出一些程序——特别是像 Firefox 和 Chrome 这样的大浏览器——不使用操作系统版本,而是自己做。
  • @milanHrabos:该函数在此答案的第三个链接中指示的行中完全定义。该定义被宏的使用所掩盖,但定义在第二个链接中可见。所以这是你能找到的最佳答案。
猜你喜欢
  • 1970-01-01
  • 2015-06-02
  • 1970-01-01
  • 2021-04-22
  • 2012-05-04
  • 2018-09-02
  • 1970-01-01
  • 2017-07-18
  • 2011-11-09
相关资源
最近更新 更多