]> code.citadel.org Git - citadel.git/blobdiff - citadel/locate_host.c
- port to Cygwin (DLL support, etc.)
[citadel.git] / citadel / locate_host.c
index 2860c6a828c647e63b295faaefd4f30a3e71be4c..e71b0cd14576cffac119a8458c21eddb25d10f68 100644 (file)
@@ -1,8 +1,14 @@
 /*
- * locate the originating host
  * $Id$
+ *
+ * locate the originating host
+ *
  */
 
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <limits.h>
 #include <netdb.h>
 #include <string.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
+#include "dynloader.h"
 #include "locate_host.h"
+#include "sysdep_decls.h"
 #include "config.h"
+#include "tools.h"
 
 void locate_host(char *tbuf, const struct in_addr *addr)
 {
-       struct hostent *ch, *ch2;
+       struct hostent *ch;
        char *i;
        int a1, a2, a3, a4;
 
+       lprintf(9, "locate_host() called\n");
+
 #ifdef HAVE_NONREENTRANT_NETDB
        begin_critical_section(S_NETDB);
 #endif
@@ -45,14 +53,17 @@ void locate_host(char *tbuf, const struct in_addr *addr)
                                   section */
        }
        /* check if the forward DNS agrees; if not, they're spoofing */
-       if ((ch2 = gethostbyname(ch->h_name)) == NULL)
+       i = strdoop(ch->h_name);
+       ch = gethostbyname(i);
+       phree(i);
+       if (ch == NULL)
                goto bad_dns;
 
        /* check address for consistency */
-       for (; *ch2->h_addr_list; ch2->h_addr_list++)
-               if (!memcmp(*ch2->h_addr_list, addr,
+       for (; *ch->h_addr_list; ch->h_addr_list++)
+               if (!memcmp(*ch->h_addr_list, addr,
                            sizeof *addr)) {
-                       strncpy(tbuf, ch->h_name, 24);
+                       safestrncpy(tbuf, ch->h_name, 25);
                        goto end;
                }
        goto bad_dns;           /* they were spoofing. report a numeric IP
@@ -64,5 +75,6 @@ void locate_host(char *tbuf, const struct in_addr *addr)
        end_critical_section(S_NETDB);
 #endif
 
-       tbuf[24] = 0;
+       tbuf[25] = 0;
+       lprintf(9, "locate_host() exiting\n");
 }