From f58c6774e4650c0395cf9ab9828b8872553b7f4f Mon Sep 17 00:00:00 2001 From: hniksic Date: Fri, 10 Oct 2003 19:27:41 -0700 Subject: [PATCH] [svn] Provide the support for int32_t and u_int32_t. --- ChangeLog | 5 +++++ configure.in | 7 ++++++- src/ChangeLog | 8 ++++++++ src/config.h.in | 11 ++++++++++- src/host.c | 18 +++++------------- src/sysdep.h | 26 ++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index c22d3479..bcf3f8ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-10-11 Hrvoje Niksic + + * configure.in: Check for int32_t and u_int32_t. Check for + SIZEOF_INT. + 2003-10-10 Hrvoje Niksic * aclocal.m4 (WGET_WITH_NLS): First check for gettext in libintl, diff --git a/configure.in b/configure.in index 8e46ff65..d5f3ffd7 100644 --- a/configure.in +++ b/configure.in @@ -157,9 +157,14 @@ AC_TYPE_SIZE_T AC_TYPE_PID_T AC_C_BIGENDIAN -# Check size of long. +dnl +dnl Check integral type sizes. +dnl +AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) +AC_CHECK_TYPES(int32_t) +AC_CHECK_TYPES(u_int32_t) dnl dnl Checks for headers diff --git a/src/ChangeLog b/src/ChangeLog index 23b5dae1..2e7fc750 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-10-11 Hrvoje Niksic + + * host.c (lookup_host): Use u_int32_t to store the result of + inet_addr(). That removes the need for offset fiddling, caring + about endian-ness, etc. + + * sysdep.h: Define int32_t and u_int32_t if not available. + 2003-10-11 Hrvoje Niksic * ftp-basic.c (ftp_epsv): Use socklen_t * as the third argument to diff --git a/src/config.h.in b/src/config.h.in index eb811e3b..c05f00c3 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -80,6 +80,9 @@ char *alloca (); significant byte first). */ #undef WORDS_BIGENDIAN +/* Define to the length of int. */ +#undef SIZEOF_INT + /* Define to the length of long. */ #undef SIZEOF_LONG @@ -271,9 +274,15 @@ char *alloca (); /* Define if you want to enable the IPv6 support. */ #undef ENABLE_IPV6 -/* Define if you don't have socklen_t. */ +/* Defined to int or size_t on systems without socklen_t. */ #undef socklen_t +/* Define if you have int32_t. */ +#undef HAVE_INT32_T + +/* Define if you have u_int32_t. */ +#undef HAVE_U_INT32_T + /* First a gambit to see whether we're on Solaris. We'll need it below. */ #ifdef __sun diff --git a/src/host.c b/src/host.c index 652edacf..d0ec7675 100644 --- a/src/host.c +++ b/src/host.c @@ -601,7 +601,7 @@ struct address_list * lookup_host (const char *host, int silent) { struct address_list *al = NULL; - unsigned long addr_ipv4; /* #### use a 32-bit type here. */ + u_int32_t addr_ipv4; ip_address addr; /* First, try to check whether the address is already a numeric @@ -612,26 +612,18 @@ lookup_host (const char *host, int silent) return address_list_from_single (&addr); #endif - addr_ipv4 = (unsigned long)inet_addr (host); - if ((int)addr_ipv4 != -1) + addr_ipv4 = (u_int32_t)inet_addr (host); + if (addr_ipv4 != (u_int32_t)-1) { /* ADDR is defined to be in network byte order, which is what - this returns, so we can just copy it to STORE_IP. However, - on big endian 64-bit architectures the value will be stored - in the *last*, not first four bytes. OFFSET makes sure that - we copy the correct four bytes. */ - int offset = 0; -#ifdef WORDS_BIGENDIAN - offset = sizeof (unsigned long) - sizeof (ip4_address); -#endif - map_ipv4_to_ip ((ip4_address *)((char *)&addr_ipv4 + offset), &addr); + this returns, so we can just copy it to STORE_IP. */ + map_ipv4_to_ip ((ip4_address *)&addr_ipv4, &addr); return address_list_from_single (&addr); } if (host_name_addresses_map) { al = hash_table_get (host_name_addresses_map, host); - if (al) { DEBUGP (("Found %s in host_name_addresses_map (%p)\n", host, al)); diff --git a/src/sysdep.h b/src/sysdep.h index a42cfa8a..2defc65a 100644 --- a/src/sysdep.h +++ b/src/sysdep.h @@ -243,4 +243,30 @@ void *memcpy (); int fnmatch (); #endif +/* Provide 32-bit types for the code that really needs it. */ + +#ifndef HAVE_INT32_T +# if SIZEOF_INT == 4 +typedef int int32_t; +# else +# if SIZEOF_LONG == 4 +typedef long int32_t; +# else + "Cannot determine a 32-bit type" +# endif +# endif +#endif + +#ifndef HAVE_U_INT32_T +# if SIZEOF_INT == 4 +typedef unsigned int u_int32_t; +# else +# if SIZEOF_LONG == 4 +typedef unsigned long u_int32_t; +# else + "Cannot determine a 32-bit type" +# endif +# endif +#endif + #endif /* SYSDEP_H */ -- 2.39.2