use syslog instead of /var/adm/rsyncd.log
[rsync/rsync.git] / socket.c
index a92cccd..5ee31f6 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -294,3 +294,50 @@ void become_daemon(void)
        close(1);
        close(2);
 }
+
+/*******************************************************************
+ return the IP addr of the client as a string 
+ ******************************************************************/
+char *client_addr(int fd)
+{
+       struct sockaddr sa;
+       struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+       int     length = sizeof(sa);
+       static char addr_buf[100];
+
+       if (getpeername(fd, &sa, &length)) {
+               exit(1);
+       }
+
+       strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf)-1);
+
+       return addr_buf;
+}
+
+
+/*******************************************************************
+ return the DNS name of the client 
+ ******************************************************************/
+char *client_name(int fd)
+{
+       struct sockaddr sa;
+       struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+       int     length = sizeof(sa);
+       static char name_buf[100];
+       struct hostent *hp;
+
+       strcpy(name_buf,"UNKNOWN");
+
+       if (getpeername(fd, &sa, &length)) {
+               exit(1);
+       }
+
+       /* Look up the remote host name. */
+       if ((hp = gethostbyaddr((char *) &sockin->sin_addr,
+                               sizeof(sockin->sin_addr),
+                               AF_INET))) {
+               strlcpy(name_buf,(char *)hp->h_name,sizeof(name_buf) - 1);
+       }
+
+       return name_buf;
+}