locate_host.c

00001 /*
00002  * $Id: locate_host.c 5147 2007-05-08 15:36:22Z ajc $
00003  */
00009 
00010 #include "webcit.h"
00011 
00018 void locate_host(char *tbuf, int client_socket)
00019 {
00020         struct sockaddr_in cs;
00021         struct hostent *ch;
00022         socklen_t len;
00023         char *i;
00024         int a1, a2, a3, a4;
00025 
00026         len = sizeof(cs);
00027         if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
00028                 strcpy(tbuf, "<unknown>");
00029                 return;
00030         }
00031         if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
00032                                 AF_INET)) == NULL) {
00033                 i = (char *) &cs.sin_addr;
00034                 a1 = ((*i++) & 0xff);
00035                 a2 = ((*i++) & 0xff);
00036                 a3 = ((*i++) & 0xff);
00037                 a4 = ((*i++) & 0xff);
00038                 sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
00039                 return;
00040         }
00041         safestrncpy(tbuf, ch->h_name, 64);
00042 }
00043 

Generated on Wed Jun 20 23:13:08 2007 for webcit by  doxygen 1.5.2