#include "Winsock.h"
#include "windows.h"
#include "stdio.h"
#pragma comment(lib,"wsock32.lib")int main()
{
char *host_name="ccc";
struct hostent *ptr;
ptr =gethostbyname(host_name);
printf(ptr->h_addr_list);
return 0;
}
主机名:ccc
错误提示:Unhandled exception in 1.exe:0xC0000005:Access Violantion
ptr->h_name断点信息:CXX0030:Error:expression cannot be evaluated
要怎么改呢
调试环境:VC++6.0
#include "windows.h"
#include "stdio.h"
#pragma comment(lib,"wsock32.lib")int main()
{
char *host_name="ccc";
struct hostent *ptr;
ptr =gethostbyname(host_name);
printf(ptr->h_addr_list);
return 0;
}
主机名:ccc
错误提示:Unhandled exception in 1.exe:0xC0000005:Access Violantion
ptr->h_name断点信息:CXX0030:Error:expression cannot be evaluated
要怎么改呢
调试环境:VC++6.0
在做判断前就有问题了
程序如下:
#include "Winsock.h"
#include "windows.h"
#include "stdio.h"
#pragma comment(lib,"wsock32.lib")int main()
{
WSADATA WSAData;
if(WSAStartup(MAKEWORD(1,1),&WSAData)!=0)
{
printf("nok\n");
}
char host_name[30]="ccc";
struct hostent *ptr;
struct in_addr ip;
int aa;
int i=0;
ptr =gethostbyname(host_name);
if(ptr!=NULL)
{
while(ptr->h_addr_list[i]!=NULL)
{
memcpy((char*)(&aa),ptr->h_addr_list[i],4);
ip.S_un.S_addr=aa;
printf("%s\n",inet_ntoa(ip));
i++;
}
printf("ptr->h_name:");
printf("%s\n",ptr->h_name);
printf("ptr->h_aliases:");
printf("%s\n",ptr->h_aliases);
printf("ptr->h_addrtype:");
printf("%d\n",ptr->h_addrtype);
printf("ptr->h_length:");
printf("%d\n",ptr->h_length);
}
else
printf("没有该主机!\n");
return 0;
}