* Attempting to add a smart host in webcit was instead adding it as an RBL host....
[citadel.git] / webcit / locate_host.c
blob8b03833d5e3a97afe148b7ada2faaead331b0e6f
1 /*
2 * $Id$
3 */
4 /**
5 * \defgroup Hostlookup Examine a socket and determine the name/address of the originating host.
6 * \ingroup WebcitHttpServer
7 */
8 /*@{*/
10 #include "webcit.h"
12 /**
13 * \brief get a hostname
14 * \todo buffersize?
15 * \param tbuf the returnbuffer
16 * \param client_socket the sock fd where the client is connected
18 void locate_host(StrBuf *tbuf, int client_socket)
20 struct sockaddr_in cs;
21 struct hostent *ch;
22 socklen_t len;
23 char *i;
24 int a1, a2, a3, a4;
26 len = sizeof(cs);
27 if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
28 StrBufAppendBufPlain(tbuf, HKEY("<unknown>"), 0);
29 return;
31 if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
32 AF_INET)) == NULL) {
33 i = (char *) &cs.sin_addr;
34 a1 = ((*i++) & 0xff);
35 a2 = ((*i++) & 0xff);
36 a3 = ((*i++) & 0xff);
37 a4 = ((*i++) & 0xff);
38 StrBufPrintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
39 return;
41 StrBufAppendBufPlain(tbuf, ch->h_name, -1, 0);
44 /*@}*/