Article View: es.comp.os.linux.programacion
Article #18509Sockets.
From: Switch
Date: Thu, 26 Aug 1999 00:00
Date: Thu, 26 Aug 1999 00:00
52 lines
2001 bytes
2001 bytes
Hola.
Estoy programando un demonio en C que recoge peticiones por un socket
(servidor).
Cuando le llega una peticion lanza un thread que la atiende.
Este Thread recibe como par�metro el identificador de socket, que m�s
adelante usa para devolver la respuesta.
El problema es que necesito saber la direcci�n IP del cliente a partir del
identificador de socket para verificar que el lugar desde el que se conecta
es v�lido.
�Como saco yo un array de caracteres que contenga la direcci�n IP del
cliente a partir del identificador de socket?
La conexi�n se acepta as�:
{
int result;
int addrlen;
struct sockaddr_in i_name;
if (listen(sock_id, 5) == -1)
return -1;
fcntl(sock_id, F_SETFL, fcntl(sock_id, F_GETFL, 0) & ~O_NONBLOCK);
/* Bucle aceptando conexiones y creando threads */
while (TRUE) {
addrlen = sizeof(i_name);
result = accept(sock_id, (struct sockaddr *)&i_name,
&addrlen);
if (result == -1) {
switch(errno) {
case ECONNABORTED:
case EINTR:
return 0;
}
return -1;
}
else {
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) &
~O_NONBLOCK);
thread_Ejecuta(result);
}
}
return 0;
}
--
Technical Details
Message-ID:
<7q33s5$j1g$1@talia.mad.ttd.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,6ff6beb816085589,start X-Google-Attributes: gidf86c8,public From: "Switch" <fros@bitel.es> Subject: Sockets. Date: 1999/08/26 Message-ID: <7q33s5$j1g$1@talia.mad.ttd.net> X-Deja-AN: 517384923 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Organization: Telefonica Transmision de Datos X-MSMail-Priority: Normal Newsgroups: es.comp.os.linux.programacion