Changeover to new room structure. See ChangeLog for details.
[citadel.git] / citadel / locate_host.c
1 /*
2  * locate the originating host
3  */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <signal.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <netinet/in.h>
12 #include <limits.h>
13 #include <netdb.h>
14 #include <string.h>
15 #include <pthread.h>
16 #include "sysdep.h"
17 #include "citadel.h"
18 #include "server.h"
19 #include "locate_host.h"
20 #include "config.h"
21
22 void locate_host(char *tbuf)
23 {
24         struct sockaddr_in      cs;     
25         struct hostent      *   ch;        
26         int                     len;     
27         char *i;
28         int a1,a2,a3,a4;
29        
30     len = sizeof(cs);   
31     if (getpeername(CC->client_socket, (struct sockaddr *)&cs,&len) < 0){   
32         strcpy(tbuf,config.c_fqdn);
33         return;
34         }
35      
36     if((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),  
37           AF_INET)) == NULL) { 
38                 i = (char *) &cs.sin_addr;
39                 a1 = ((*i++)&0xff);
40                 a2 = ((*i++)&0xff);
41                 a3 = ((*i++)&0xff);
42                 a4 = ((*i++)&0xff);
43                 sprintf(tbuf,"%d.%d.%d.%d",a1,a2,a3,a4);
44                 return;
45                 }
46
47         strncpy(tbuf,ch->h_name, 24);
48         tbuf[24] = 0;
49         }