5 * \defgroup Hostlookup Examine a socket and determine the name/address of the originating host.
6 * \ingroup WebcitHttpServer
13 * \brief get a hostname
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;
27 if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
28 StrBufAppendBufPlain(tbuf, HKEY("<unknown>"), 0);
31 if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
33 i = (char *) &cs.sin_addr;
38 StrBufPrintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
41 StrBufAppendBufPlain(tbuf, ch->h_name, -1, 0);