Foros del Web » Administración de Sistemas » Unix / Linux »

Problema con la función gethostbyname

Estas en el tema de Problema con la función gethostbyname en el foro de Unix / Linux en Foros del Web. Hola: tengo el siguiente trozo de código: int Servidor_Crea_Conexion_Inet(int puerto) { int sock; int res; struct sockaddr_in si; struct hostent *hp; char maquina[20]; sock=-1; sock=socket(AF_INET,SOCK_STREAM,0); ...
  #1 (permalink)  
Antiguo 04/02/2005, 02:35
 
Fecha de Ingreso: febrero-2005
Mensajes: 3
Antigüedad: 19 años, 2 meses
Puntos: 0
Problema con la función gethostbyname

Hola:

tengo el siguiente trozo de código:

int Servidor_Crea_Conexion_Inet(int puerto)
{
int sock;
int res;
struct sockaddr_in si;
struct hostent *hp;
char maquina[20];

sock=-1;

sock=socket(AF_INET,SOCK_STREAM,0);

if (sock!= -1)
{
gethostname(maquina, sizeof (maquina));
hp=gethostbyname(maquina);
if (hp==NULL)
printf ("Error %d en funcion gethostbyname\n",errno);
else
{
memset(&si,0,sizeof(struct sockaddr_in));
si.sin_family=AF_INET;
si.sin_port=htons(puerto);
memmove(&si.sin_addr, hp->h_addr,hp->h_length);
res=bind(sock,(struct sockaddr *)&si, sizeof(si));
if (res!= -1)
{
res=listen(sock,5);
if (res==-1)
sock=-1;
}
else
sock=-1;
}
}
else
printf ("Error %d en la funcion socket\n",errno);

return sock;
}

Esta función me da siempre que la ejecuto un puntero a null en la función gethostbyname, y no me crea el socket de conexión.
¿Alguien puede ayudarme?.

Gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:47.