* When saving a Task, if the status is COMPLETED then also set PERCENT-COMPLETE:100...
[citadel.git] / webcit / locate_host.c
blob7b5869907c8cb3cdb9c54e13295b3a5689c43ff4
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(char *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 strcpy(tbuf, "<unknown>");
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 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
39 return;
41 safestrncpy(tbuf, ch->h_name, 64);
44 /*@}*/