char nombreHost[100];
struct sockaddr_un direccUNIXServidor;
struct sockaddr_in direccINETServidor;
struct sockaddr* puntDireccSockServidor;
struct hostent* estructHost;
struct in_addr* nodoHost;
/* Abriremos un socket cliente con un nombre y tipo específico */
internet = direccionInternet ( nombre ); /* ¿es socket internet? */
dominio = internet ? AF_INET : AF_UNIX;
dfCliente = socket (dominio, SOCK_STREAM, PROTOCOLO_DEFECTO);
if (dfCliente == -1)
{
Xerror(ERRORBORRAR);
return(FALSE);
}
if (internet) /* es un socket internet */
{
obtenerHostyPuerto (nombre, nombreHost, &puerto);
if (nombreHost[0] == NULL) gethostname (nombreHost,100);
direccINETServidor.sin_family = AF_INET;
estructHost = gethostbyname (nombreHost);
if (estructHost==NULL)
{
Xerror(ERRORBORRAR);
return (FALSE);
}
nodoHost = (struct in_addr*) estructHost->h_addr;
/*printf("Direccion IP %s \n", inet_ntoa (*nodoHost));*/
direccINETServidor.sin_addr = *nodoHost; /* nos da la direccion IP */
direccINETServidor.sin_port = puerto; /* nos da el puerto de comunic */
puntDireccSockServidor = (struct sockaddr*) &direccINETServidor;
longServidor = sizeof (direccINETServidor);
}
else /* socket del dominio UNIX */
{
direccUNIXServidor.sun_family = AF_UNIX;
strcpy (direccUNIXServidor.sun_path, nombre);
puntDireccSockServidor = (struct sockaddr*) &direccUNIXServidor;
longServidor = sizeof (direccUNIXServidor);
}
do /* conexion a un servidor */
{
resultado = connect (dfCliente, puntDireccSockServidor, longServidor);
if (resultado == -1) { sleep (SOCKET_DORMIR); time_out++; }
if (time_out == 2 ) {
Xerror(ERRORBORRAR);
return(FALSE);
}
}
while (resultado == -1);
close (dfCliente); /* cierra el descriptor del fichero cliente */
return (TRUE);
} /* fin de borraServer */
/*
*---------------------------------------------------------------------
*
* PROTOTIPO: void trataSignal ( void )
*
* DESCRIPCION: especifica la acción a tomar al llegar cada
* una de las señales definidas posibles
*
*---------------------------------------------------------------------
*/
void trataSignal ( void )
{
signal ( SIGPANT, XmanejaPantalla );
signal ( SIGERRCMD, manejaErrorCmd );
signal ( SIGERRSERBACK, manejaErrorSerBack );
signal ( SIGERRCLISOCK, manejaErrorCliSock );
signal ( SIGERRSERSOCK, manejaErrorSerSock );
signal ( SIGERRREDIREC, manejaErrorRedirec );
signal ( SIGDIBUJAR, manejaDibujar );
}