From: Robert Bunn Date: 2005-06-30T21:40:42+09:00 Subject: Re: hostent problem wrote in message news:1120131331.929300.236040@f14g2000cwb.googlegroups.com... > Hi, > I want to get the IP address of my machine in my program and for that i > have written the following code. > I don't know why the gethostbyname() is not returning the correct > hostent structure. > > hp = new hostent[]; I think this shouldn't compile, and MinGW agrees. You can't omit the size of an array allocated using new. You don't want to allocate it anyway. You just want a pointer: hostent* hp; > TCHAR str[MAX_COMPUTERNAME_LENGTH+1]; > TCHAR result[MAX_COMPUTERNAME_LENGTH+1]; > > GetComputerName(str,&len); > hp = gethostbyname(str); > if(hp!=NULL) > { > memcpy(result, hp->h_name, sizeof(result)); > OR > result=(TCHAR*)hp->h_name; > } > > The result that i am getting the hp=NULL.