hi,
i have this code :

Code:
#include <stdio.h>#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>


int main()
{
 char *hostname = "ddr";
 struct addrinfo hints, *res;
 struct in_addr *addr;
 int err;
 char gg[50];
 memset(&hints, 0, sizeof(hints));
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_family = AF_INET;


 if ((err = getaddrinfo(hostname, NULL, &hints, &res)) != 0) 
 {
  printf("error %d\n", err);
  return 1;
 }


 addr->s_addr = ((struct sockaddr_in *)(res->ai_addr))->sin_addr.s_addr;
  gg = inet_ntoa(addr);
 /*printf("official host name: %s\n",h->h_name);*/
 printf("ip address : %s\n", gg);


 freeaddrinfo(res);


 return 0;
}
and i want to get the following output:
/*
official host name: ddr
internet address: 127.0.1.1 (7F000101)
*/
where (7F000101) is by the inet_ntoa() obtained info.

with this code i can get the desired info:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


int main(void)
{
  struct hostent *h;
  struct in_addr *a;


  if((h=gethostbyname("ddr"))==NULL) exit(1);
    printf("official host name: %s\n",h->h_name);


  a=(struct in_addr*)h->h_addr_list[0];
  printf("internet address: %s (%08lX)\n",inet_ntoa(*a),(long unsigned int)ntohl(a->s_addr));


  exit(0);
 
}

but witht the 1 code i am not able for some reason, first of all i am getting the following warning when i compile the 1 code:
gcc tt.c -o tt
tt.c: In function ‘main’:
tt.c:29:5: error: incompatible types when assigning to type ‘char[50]’ from type ‘int’
make: *** [tt] Error 1

and i dont know why i getting that error, i think that i am doing everything ok, the inet_ntoa returns a char * and gg is also a char*, so what is the problem?

i thank you in advance for the help