Ver Mensaje Individual
  #2  
Antiguo 24-08-2012
Gerson12 Gerson12 is offline
Miembro
NULL
 
Registrado: abr 2012
Ubicación: Peru-Lima
Posts: 138
Reputación: 13
Gerson12 Va por buen camino
en la biblioteca <netdb.h> exite una funcion cuya declaracion es la siguiente.
Código:
Código:
struct hostent *gethostbyname(char *name);
aqui tienes un ejemplo de como usarla:
Código:
Código:
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

struct sockaddr whereto;
struct hostent *hp;
struct sockaddr_in *to;
char *target;
char *hostname;
 
memset(&whereto, 0, sizeof(struct sockaddr));
to = (struct sockaddr_in *)&whereto;
to->sin_family = AF_INET;
to->sin_addr.s_addr = inet_addr(target);
if (to->sin_addr.s_addr != -1)
   hostname = target;
else
{
   hp = gethostbyname(target);
   if (!hp)
      printf("host desconocido%s\n", target);
   else
   {
      to->sin_family = hp->h_addrtype;
      memcpy(&(to->sin_addr.s_addr), hp->h_addr, hp->h_length);
      hostname = hp->h_name;
      printf("gethostbyname ejecutado correctamente\n");
   }
}
esto no lo hize yo pero lo busque en san google amigo ^^ espero que te valga si necesitas la fuente donde la saque avisame ya que tengo entendi que no se dejan enlaces o algo asi
__________________
Gracias a todos por apoyarme ^^
Responder Con Cita