#ifndef computer_h_
#define computer_h_
#include<iostream>
class computer
{
private:
enum {a=50};
char ipaddr[a];
char hostname[a];
public:
computer();
void  getlocalname();
void  getipaddr();
void  getall();
void  show();
~computer();
};
#endif
#include"computer.h"
#include"winsock2.h"
#include<iostream>
#include<cstring>
#pragma comment(lib,"wsock32.lib")
using namespace std;
computer::computer()
{
hostname[0]='\0';
ipaddr[0]='\0';
}
void computer::getlocalname()
{
char name[50];
int code=gethostname(name,sizeof(name));
if(code!=0)
{
cerr<<"error!-failed to get hostname";
exit(1);
}
strncpy(hostname,name,49);
hostname[49]='\0';
}
void computer::getipaddr()
{
struct hostent * host=gethostbyname(hostname);
if(host==NULL)
{
cerr<<"error! failed to get ip address";
exit(1);

}
LPSTR lpaddr=host->h_addr_list[0];
if(lpaddr==NULL)
{
cerr<<"error?!";
}
struct in_addr inaddr;
memmove(&inaddr,lpaddr,4);
char* temp=inet_ntoa(inaddr);
if(temp==NULL)
{
cerr<<"error!";
exit(1);

}
strncpy(ipaddr,temp,49);
ipaddr[49]='\0';
}
void computer::getall( )
{
getlocalname();
getipaddr();
}
void computer::show()
{
cout<<"the name is:"<<hostname<<endl;
cout<<"the ipaddr is:"<<ipaddr<<endl;
}
computer::~computer()
{
}请各位帮忙看看哪儿错了,这是主要的一部分,好像结果不对。