[进者有分]c 中gethostbyname()的源代码是什么?

ThunderLight 2006-11-16 09:44:45
最近在使用boa webserver
但是一执行 boa -c ../conf
就立即报错
gethostbyname::No such file or directory
所以怀疑boa程序调用的gethostbyname中有需要的文件在我这个潜入式系统中不存在
所以想看看gethostbyname()的源码?
还有gethostname()也一块看看
谢谢

进者都有分
...全文
1329 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
yejun307 2006-11-16
  • 打赏
  • 举报
回复
看来多数问题我是心有余而力不足啊!
SaintKaKa 2006-11-16
  • 打赏
  • 举报
回复
学习下
malligator 2006-11-16
  • 打赏
  • 举报
回复
jf
boot2006 2006-11-16
  • 打赏
  • 举报
回复
vi + cscope
ThunderLight 2006-11-16
  • 打赏
  • 举报
回复
谢谢boot2006()
wybing(Hello World!) 说的对亚

请问boot2006()如何去查源代码?
我现在只能一层层的去查源代码了,就像wybing(Hello World!)所说的gethostbyname()又会扯上其它了



下午解贴,大家都有分
只是分值不一样而已
tyc_2000_ren 2006-11-16
  • 打赏
  • 举报
回复
jf
wybing 2006-11-16
  • 打赏
  • 举报
回复
估计gethostbyname()又会扯上其它了
到在内核源代码里面找找.应该能找到.
wuwen19 2006-11-16
  • 打赏
  • 举报
回复
分分啊。
boot2006 2006-11-16
  • 打赏
  • 举报
回复
struct hostent *gethostbyname(const char *name)
{
DNS_CONTEXT c;
int ret;
struct hostent *h;

#if DNS_DEBUG
printf("gethostbyname(%s)\n",name);
#endif

// try for cached address from a previous lookup...
h=getHostFromCache(name);
if(h)
return h;

// not a totally valid thing to do here, but we check for numeric address's
// here anyway...(makes higher level code simpler)
h=gethostbyaddr(name,4,1);
if(h)
return h;

// ok, it's not a numeric address and it's not in the DNS cache,
// so we'll have to do a proper DNS lookup...
c.name=name;
c.ns[0]=nameserver[0];
c.ns[1]=nameserver[1];
c.ns[2]=nameserver[2];
c.ns[3]=nameserver[3];

ret=dns_sendQuery(&c);
if(ret<0)
return NULL;

ret=dns_getResponse(&c);
if(ret==0)
{
return addCacheEntry(&c);
}

return NULL;
}
飞哥 2006-11-16
  • 打赏
  • 举报
回复
我有个c++的
================
#include "StdAfx.h"
#include "windows.h"
#include <winsock.h>
#include "iostream.h"
#include "string.h"

#pragma comment(lib,"ws2_32.lib")

void getip(void)
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
PHOSTENT hostinfo;

wVersionRequested = MAKEWORD( 2, 0 );

//initilize this process
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
//get host name
if( gethostname ( name, sizeof(name)) == 0)
{
//get host information
if((hostinfo = gethostbyname(name)) != NULL)
{
//convert to ip string
LPCSTR ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
cout<<ip<<'\n';
}
}
//free
WSACleanup();
}
}
void main(void)
{
getip();
}
hailongchang 2006-11-16
  • 打赏
  • 举报
回复
你说的有道理,一般gethostbyname是读取这个文件,你看看你那有没有

/etc/resolv.conf

没有的话自己建立一个,重新试一下
ThunderLight 2006-11-16
  • 打赏
  • 举报
回复
我一直觉得是这么一个问题

gethostbyname的功能是根据host名称取得其他相关信息,
但是他是怎么取得的呢?我猜测是去读取一个存有host名称的host的信息文件

而我的嵌入是系统恰恰丢失了这个信息文件,所以造成报错

那么我就想去看看gethostbyname源代码,到底它去哪个文件里读取数据了
alan001 2006-11-16
  • 打赏
  • 举报
回复
不太懂 GCC
ThunderLight 2006-11-16
  • 打赏
  • 举报
回复
谢谢 hailongchang(novice)

还有一个情况忘说了

我的这个程序在 fedoracore5下面没有问题
可以正常启动
但是用arm-linux-gcc 编译以后拿到嵌入是系统下以后就不能启动了
提示:gethostbyname::No such file or directory
hailongchang 2006-11-16
  • 打赏
  • 举报
回复
帮你搜了一下,好象是个安装bug,看一下这里,重点是最后一个人的回复

http://mhonarc.axis.se/dev-etrax/msg00955.html
ThunderLight 2006-11-16
  • 打赏
  • 举报
回复
谢谢,Aaron_Jerry(善感之心) (
但是我要的是源代码
我需要去读他的源代码
看看我的linux缺少了什么文件
Aaron_Jerry 2006-11-16
  • 打赏
  • 举报
回复
HOSTENT
Windows Sockets allocates this structure is allocated. An application should never attempt to modify this structure or to free any of its components. Furthermore, only one copy of this structure is allocated per thread, and so the application should copy any information that it needs before issuing any other Windows Sockets API calls.

struct hostent {
char FAR * h_name;
char FAR * FAR * h_aliases;
short h_addrtype;
short h_length;
char FAR * FAR * h_addr_list;
};

Members
h_name
Official name of the host (PC).If using the DNS or similar resolution system, it is the Fully Qualified Domain Name (FQDN) that caused the server to return a reply. If using a local "hosts" file, it is the first entry after the IP address.
h_aliases
A NULL-terminated array of alternate names.
h_addrtype
The type of address being returned.
h_length
The length, in bytes, of each address.
h_addr_list
A NULL-terminated list of addresses for the host. Addresses are returned in network byte order. The macro h_addr is defined to be h_addr_list[0] for compatibility with older software.
Aaron_Jerry 2006-11-16
  • 打赏
  • 举报
回复
gethostbyname
The Windows Sockets gethostbyname function retrieves host information corresponding to a host name from a host database.

struct hostent FAR * gethostbyname (
const char FAR * name
);

Parameters
name
[out] A pointer to the null-terminated name of the host to resolve.
Remarks
The gethostbyname function returns a pointer to a HOSTENT structure — a structure allocated by Windows Sockets. The HOSTENT structure contains the results of a successful search for the host specified in the name parameter.

The application must never attempt to modify this structure or to free any of its components. Furthermore, only one copy of this structure is allocated per thread, so the application should copy any information it needs before issuing any other Windows Sockets function calls.

The gethostbyname function cannot resolve IP address strings passed to it. Such a request is treated exactly as if an unknown host name were passed. Use inet_addr to convert an IP address string the string to an actual IP address, then use another function, gethostbyaddr, to obtain the contents of the HOSTENT structure.

The gethostbyname function resolves the string returned by a successful call to gethostname.

Return Values
If no error occurs, gethostbyname returns a pointer to the HOSTENT structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes
WSANOTINITIALISED A successful WSAStartup must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAHOST_NOT_FOUND Authoritative Answer Host not found.
WSATRY_AGAIN Non-Authoritative Host not found, or server failure.
WSANO_RECOVERY Nonrecoverable error occurred.
WSANO_DATA Valid name, no data record of requested type.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEFAULT The name parameter is not a valid part of the user address space.
WSAEINTR A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.


QuickInfo
Windows NT: Yes
Windows: Yes
Windows CE: Use version 1.0 and later.
Header: Declared in winsock2.h.
Import Library: Link with ws2_32.lib.

cy2005abc 2006-11-16
  • 打赏
  • 举报
回复
ding
feeling_68 2006-11-16
  • 打赏
  • 举报
回复
看看MSDN上有没介绍
加载更多回复(16)

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧