/*
- * 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>
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)
* | 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;
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) {
#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;
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;
#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;
#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;
}
#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;
char tmpserv[16];
char buffer[2048];
int error;
-
+
if (serv) {
snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
if (strlen(tmpserv) > servlen)
}
#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