Delete trailing whitespace.
[freeradius.git] / src / lib / getaddrinfo.c
index 0ad79de..9171bb7 100644 (file)
@@ -1,30 +1,20 @@
 /*
- * These functions are defined and used only if the configure 
+ * These functions are defined and used only if the configure
  * cannot detect the standard getaddrinfo(), freeaddrinfo(),
  * gai_strerror() and getnameinfo(). This avoids sprinkling of ifdefs.
  *
- * FIXME: getaddrinfo() & getnameinfo() should 
+ * FIXME: getaddrinfo() & getnameinfo() should
  *        return all IPv4 addresses provided by DNS lookup.
  */
 
 #include       <freeradius-devel/ident.h>
 RCSID("$Id$")
 
-#include       <freeradius-devel/autoconf.h>
+#include       <freeradius-devel/libradius.h>
 
-#include       <stdio.h>
-#include       <string.h>
-#include       <stdlib.h>
-#include       <netdb.h>
-#include       <sys/types.h>
-#include       <sys/socket.h>
-#include       <netinet/in.h>
-#include       <arpa/inet.h>
 #include       <ctype.h>
 #include       <sys/param.h>
 
-#include       <freeradius-devel/missing.h>
-
 #ifdef HAVE_PTHREAD_H
 #include       <pthread.h>
 
@@ -39,12 +29,14 @@ static pthread_mutex_t lrad_hostbyname_mutex;
 static pthread_mutex_t lrad_hodtbyaddr_mutex;
 #endif
 
-#ifndef GETHOSTBYNAMERSTYLE 
+#undef LOCAL_GETHOSTBYNAMERSTYLE
+#ifndef GETHOSTBYNAMERSTYLE
 #define LOCAL_GETHOSTBYNAMERSTYLE 1
 #elif (GETHOSTBYNAMERSTYLE != SYSVSTYLE) && (GETHOSTBYNAMERSTYLE != GNUSTYLE)
 #define LOCAL_GETHOSTBYNAMERSTYLE 1
 #endif /* GETHOSTBYNAMERSTYLE */
 
+#undef LOCAL_GETHOSTBYADDRR
 #ifndef GETHOSTBYADDRRSTYLE
 #define LOCAL_GETHOSTBYADDRR 1
 #elif (GETHOSTBYADDRRSTYLE != SYSVSTYLE) && (GETHOSTBYADDRRSTYLE != GNUSTYLE)
@@ -70,14 +62,14 @@ static pthread_mutex_t lrad_hodtbyaddr_mutex;
  * | h_name\0alias_array\0h_aliases\0..\0addr_array\0h_addr_list\0 |
  *  ---------------------------------------------------------------
  */
-#if (LOCAL_GETHOSTBYNAMER == 1) || (LOCAL_GETHOSTBYADDRR == 1)
+#if defined(LOCAL_GETHOSTBYNAMER) || defined(LOCAL_GETHOSTBYADDRR)
 #define BUFFER_OVERFLOW 255
 int copy_hostent(struct hostent *from, struct hostent *to,
            char *buffer, int buflen, int *error)
 {
     int i, len;
     char *ptr = buffer;
-    
+
     *error = 0;
     to->h_addrtype = from->h_addrtype;
     to->h_length = from->h_length;
@@ -110,7 +102,7 @@ int copy_hostent(struct hostent *from, struct hostent *to,
     to->h_addr_list = (char**)ptr;
     for(i = 0; (int *)from->h_addr_list[i] != 0; i++);
     ptr += (i+1) * sizeof(int *);
-     
+
     for(i = 0; (int *)from->h_addr_list[i] != 0; i++) {
        len = sizeof(int);
        if ((ptr-buffer)+len < buflen) {
@@ -129,7 +121,7 @@ int copy_hostent(struct hostent *from, struct hostent *to,
 
 #ifdef LOCAL_GETHOSTBYNAMERSTYLE
 static struct hostent *
-gethostbyname_r(const char *hostname, struct hostent *result, 
+gethostbyname_r(const char *hostname, struct hostent *result,
            char *buffer, int buflen, int *error)
 {
     struct hostent *hp;
@@ -142,7 +134,7 @@ gethostbyname_r(const char *hostname, struct hostent *result,
     pthread_mutex_lock(&lrad_hostbyname_mutex);
 #endif
 
-    hp = gethostbyname(name);
+    hp = gethostbyname(hostname);
     if ((!hp) || (hp->h_addrtype != AF_INET) || (hp->h_length != 4)) {
         *error = h_errno;
          hp = NULL;
@@ -160,10 +152,10 @@ gethostbyname_r(const char *hostname, struct hostent *result,
 #endif /* GETHOSTBYNAMERSTYLE */
 
 
-#ifdef LOCAL_GETHOSTBYADDRRSTYLE
+#ifdef LOCAL_GETHOSTBYADDRR
 static struct hostent *
 gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result,
-           char *buffer, int buflen, int *error)
+               char *buffer, int buflen, int *error)
 {
     struct hostent *hp;
 
@@ -336,7 +328,7 @@ getaddrinfo(const char *hostname, const char *servname,
 #if GETHOSTBYNAMERSTYLE == SYSVSTYLE
     hp = gethostbyname_r(hostname, &result, buffer, sizeof(buffer), &error);
 #elif GETHOSTBYNAMERSTYLE == GNUSTYLE
-    if (gethostbyname_r(hostname, &result, buffer, 
+    if (gethostbyname_r(hostname, &result, buffer,
          sizeof(buffer), &hp, &error) != 0) {
                hp = NULL;
        }
@@ -376,9 +368,9 @@ getaddrinfo(const char *hostname, const char *servname,
 
 #ifndef HAVE_GETNAMEINFO
 int
-getnameinfo(const struct sockaddr *sa, socklen_t salen, 
-               char *host, size_t hostlen, 
-               char *serv, size_t servlen, 
+getnameinfo(const struct sockaddr *sa, socklen_t salen,
+               char *host, size_t hostlen,
+               char *serv, size_t servlen,
                unsigned int flags)
 {
     struct sockaddr_in *sin = (struct sockaddr_in *)sa;
@@ -387,7 +379,7 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen,
     char tmpserv[16];
     char buffer[2048];
     int error;
-  
+
     if (serv) {
         snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
         if (strlen(tmpserv) > servlen)
@@ -422,7 +414,7 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen,
             }
 #else
             hp = gethostbyaddr_r((char *)&sin->sin_addr,
-                               sizeof(struct in_addr), AF_INET, 
+                               sizeof(struct in_addr), AF_INET,
                               &result, buffer, sizeof(buffer), &error);
 #endif
 #else