linux环境下gethostbyname函数问题 - C/C++ / C语言
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
for(x2=0;hp->h_addr_list[x2];++x2)
{
strcpy(AlarmDevIP,inet_ntoa(*(struct in_addr*)hp->h_addr_list[x2]));
}
printf("%s", AlarmDevIP);
}
else
{
printf("get host by name error\n");
}
发现得到的结果总是 error,请问这个函数对程序所在的环境有要求,我测试环境在公司内网,要通过网关才能到外网的,另外呢知道这个函数的实现是怎么个过程吗?谢谢!
没有初始化
int main( void )
{
WSADATA wsadata;
WSAStartup(MAKEWORD(2,2),&wsadata);
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
for(x2=0;hp->h_addr_list[x2];++x2)
{
strcpy(AlarmDevIP,inet_ntoa(*(struct in_addr*)hp->h_addr_list[x2]));
}
printf("%s", AlarmDevIP);
}
else
{
printf("get host by name error\n");
}
return 0;
}
#include <netdb.h>
#include <sys/so
相关问答:
现在有关c++、c的书籍,那些书是较深层次的?请介绍几本?
#include <iostream>
using namespace std;
int funhion(int x, int y )
{
int m,n;
  ......
请问各位高手如何用C/C++获得系统未安装补丁
好像很专业的东西。。。
查注册表
每个补丁如果安装了都会在注册表里面登记
请问能不能更清晰些,我想用c\c++查出来,不好意思,我是新手。还望指教。谢
分值 ......
C盘上多的文件名为:dosh , Recycled ,System Volum information, AUTOEXEC.BAT, BOOT.INT , bootfoot.bin, CONFIG.SYS,IO.SYS, MSDOS.SYS, DETECT.COM ,ntldr, pagefile.sys;
而且每个盘上都有这些文件:RECYCLER ......
背景:
--------
头文件db_method.h经过美化后存在下面几种结构定义类型
typedef struct
{
BYTE id;
BYTE idAsync;
DM_T dmInfo;
CHAR tbName[MAX_TBNAME_LEN];
} REC ......