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(char *tbuf
, int client_socket
)
20 struct sockaddr_in cs
;
27 if (getpeername(client_socket
, (struct sockaddr
*) &cs
, &len
) < 0) {
28 strcpy(tbuf
, "<unknown>");
31 if ((ch
= gethostbyaddr((char *) &cs
.sin_addr
, sizeof(cs
.sin_addr
),
33 i
= (char *) &cs
.sin_addr
;
38 sprintf(tbuf
, "%d.%d.%d.%d", a1
, a2
, a3
, a4
);
41 safestrncpy(tbuf
, ch
->h_name
, 64);