From 64ba6e4cc3a0ccf8c8c6349fa75b937ca9bad9a6 Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Fri, 22 Jan 1999 04:35:11 +0000 Subject: [PATCH] make this go on the Alpha. --- acconfig.h | 2 + config.h.in | 3 + configure | 66 ++++++++++++- configure.in | 9 +- lib/dns/rbt.c | 3 +- lib/dns/rdata/in_1/a_1.c | 14 ++- lib/dns/rdata/in_1/a_1.h | 14 ++- lib/dns/rdata/in_1/wks_11.c | 13 +-- lib/dns/rdata/in_1/wks_11.h | 13 +-- lib/dns/redblack.c | 3 +- lib/isc/Makefile.in | 3 +- lib/isc/include/isc/inet.h | 36 +++++++ lib/isc/inet_ntop.c | 187 ++++++++++++++++++++++++++++++++++++ 13 files changed, 336 insertions(+), 30 deletions(-) create mode 100644 acconfig.h create mode 100644 lib/isc/include/isc/inet.h create mode 100644 lib/isc/inet_ntop.c diff --git a/acconfig.h b/acconfig.h new file mode 100644 index 0000000000..4166ad9526 --- /dev/null +++ b/acconfig.h @@ -0,0 +1,2 @@ +/* define if you need inet_ntop() */ +#undef NEED_INET_NTOP diff --git a/config.h.in b/config.h.in index 8f84b6228e..e83e12d0b1 100644 --- a/config.h.in +++ b/config.h.in @@ -15,6 +15,9 @@ /* Define if you can safely include both and . */ #undef TIME_WITH_SYS_TIME +/* define if you need inet_ntop() */ +#undef NEED_INET_NTOP + /* Define if you have the header file. */ #undef HAVE_FCNTL_H diff --git a/configure b/configure index 274cf85fcd..7ed1440286 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh -# From configure.in Revision: 1.8 +# From configure.in Revision: 1.9 # Guess values for system-dependent variables and create Makefiles. # Generated automatically using autoconf version 2.12 @@ -1367,8 +1367,65 @@ fi fi + +echo $ac_n "checking for inet_ntop""... $ac_c" 1>&6 +echo "configure:1373: checking for inet_ntop" >&5 +if eval "test \"`echo '$''{'ac_cv_func_inet_ntop'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char inet_ntop(); + +int main() { + +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_inet_ntop) || defined (__stub___inet_ntop) +choke me +#else +inet_ntop(); +#endif + +; return 0; } +EOF +if { (eval echo configure:1401: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then + rm -rf conftest* + eval "ac_cv_func_inet_ntop=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_func_inet_ntop=no" +fi +rm -f conftest* +fi + +if eval "test \"`echo '$ac_cv_func_'inet_ntop`\" = yes"; then + echo "$ac_t""yes" 1>&6 + : +else + echo "$ac_t""no" 1>&6 +ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS inet_ntop.o" + + cat >> confdefs.h <<\EOF +#define NEED_INET_NTOP 1 +EOF + + +fi + + echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 -echo "configure:1372: checking whether ${MAKE-make} sets \${MAKE}" >&5 +echo "configure:1429: checking whether ${MAKE-make} sets \${MAKE}" >&5 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1397,7 +1454,7 @@ fi # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1401: checking for $ac_word" >&5 +echo "configure:1458: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1434,7 +1491,7 @@ fi # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:1438: checking for a BSD compatible install" >&5 +echo "configure:1495: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -1673,6 +1730,7 @@ s%@host_vendor@%$host_vendor%g s%@host_os@%$host_os%g s%@CC@%$CC%g s%@CPP@%$CPP%g +s%@ISC_EXTRA_OBJS@%$ISC_EXTRA_OBJS%g s%@SET_MAKE@%$SET_MAKE%g s%@RANLIB@%$RANLIB%g s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g diff --git a/configure.in b/configure.in index 1fedd0ea4f..d1c64d6fc6 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ -AC_REVISION($Revision: 1.9 $) +AC_REVISION($Revision: 1.10 $) AC_INIT(lib/dns/name.c) AC_CONFIG_HEADER(config.h) @@ -23,6 +23,13 @@ AC_CHECK_LIB(xnet, socket,, AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, inet_ntoa) ) + +AC_CHECK_FUNC(inet_ntop, , + [ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS inet_ntop.o" + AC_SUBST(ISC_EXTRA_OBJS) + AC_DEFINE(NEED_INET_NTOP)] +) + AC_PROG_MAKE_SET AC_PROG_RANLIB AC_PROG_INSTALL diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index bafef56509..878602f85a 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -15,10 +15,11 @@ * SOFTWARE. */ +#include + #include #include #include -#include #include #include diff --git a/lib/dns/rdata/in_1/a_1.c b/lib/dns/rdata/in_1/a_1.c index de4f153d10..81d0b4160b 100644 --- a/lib/dns/rdata/in_1/a_1.c +++ b/lib/dns/rdata/in_1/a_1.c @@ -15,16 +15,20 @@ * SOFTWARE. */ - /* $Id: a_1.c,v 1.6 1999/01/22 00:36:58 marka Exp $ */ + /* $Id: a_1.c,v 1.7 1999/01/22 04:35:10 explorer Exp $ */ #ifndef RDATA_IN_1_A_1_H #define RDATA_IN_1_A_1_H +#include + #include +#include + #include #include -#include -#include + +#include static dns_result_t fromtext_in_a(dns_rdataclass_t class, dns_rdatatype_t type, @@ -63,8 +67,8 @@ totext_in_a(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) { origin = origin; /* unused */ isc_buffer_available(target, ®ion); - if (inet_ntop(AF_INET, rdata->data, - region.base, region.length) == NULL) + if (isc_inet_ntop(AF_INET, rdata->data, + region.base, region.length) == NULL) return (DNS_R_NOSPACE); isc_buffer_add(target, strlen(region.base)); diff --git a/lib/dns/rdata/in_1/a_1.h b/lib/dns/rdata/in_1/a_1.h index 1f7f93b0fd..f3130e5196 100644 --- a/lib/dns/rdata/in_1/a_1.h +++ b/lib/dns/rdata/in_1/a_1.h @@ -15,16 +15,20 @@ * SOFTWARE. */ - /* $Id: a_1.h,v 1.6 1999/01/22 00:36:58 marka Exp $ */ + /* $Id: a_1.h,v 1.7 1999/01/22 04:35:10 explorer Exp $ */ #ifndef RDATA_IN_1_A_1_H #define RDATA_IN_1_A_1_H +#include + #include +#include + #include #include -#include -#include + +#include static dns_result_t fromtext_in_a(dns_rdataclass_t class, dns_rdatatype_t type, @@ -63,8 +67,8 @@ totext_in_a(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) { origin = origin; /* unused */ isc_buffer_available(target, ®ion); - if (inet_ntop(AF_INET, rdata->data, - region.base, region.length) == NULL) + if (isc_inet_ntop(AF_INET, rdata->data, + region.base, region.length) == NULL) return (DNS_R_NOSPACE); isc_buffer_add(target, strlen(region.base)); diff --git a/lib/dns/rdata/in_1/wks_11.c b/lib/dns/rdata/in_1/wks_11.c index 97b63c0518..7ac4bd08ff 100644 --- a/lib/dns/rdata/in_1/wks_11.c +++ b/lib/dns/rdata/in_1/wks_11.c @@ -15,21 +15,22 @@ * SOFTWARE. */ - /* $Id: wks_11.c,v 1.2 1999/01/22 00:36:59 marka Exp $ */ + /* $Id: wks_11.c,v 1.3 1999/01/22 04:35:10 explorer Exp $ */ #ifndef RDATA_IN_1_WKS_11_H #define RDATA_IN_1_WKS_11_H -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include static dns_result_t fromtext_in_wks(dns_rdataclass_t class, dns_rdatatype_t type, @@ -124,7 +125,7 @@ totext_in_wks(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) { origin = origin; dns_rdata_toregion(rdata, &sr); isc_buffer_available(target, &tr); - if (inet_ntop(AF_INET, sr.base, tr.base, tr.length) == NULL) + if (isc_inet_ntop(AF_INET, sr.base, tr.base, tr.length) == NULL) return (DNS_R_NOSPACE); isc_buffer_add(target, strlen(tr.base)); isc_region_consume(&sr, 4); diff --git a/lib/dns/rdata/in_1/wks_11.h b/lib/dns/rdata/in_1/wks_11.h index 312607a2a9..493297975a 100644 --- a/lib/dns/rdata/in_1/wks_11.h +++ b/lib/dns/rdata/in_1/wks_11.h @@ -15,21 +15,22 @@ * SOFTWARE. */ - /* $Id: wks_11.h,v 1.2 1999/01/22 00:36:59 marka Exp $ */ + /* $Id: wks_11.h,v 1.3 1999/01/22 04:35:10 explorer Exp $ */ #ifndef RDATA_IN_1_WKS_11_H #define RDATA_IN_1_WKS_11_H -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include static dns_result_t fromtext_in_wks(dns_rdataclass_t class, dns_rdatatype_t type, @@ -124,7 +125,7 @@ totext_in_wks(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) { origin = origin; dns_rdata_toregion(rdata, &sr); isc_buffer_available(target, &tr); - if (inet_ntop(AF_INET, sr.base, tr.base, tr.length) == NULL) + if (isc_inet_ntop(AF_INET, sr.base, tr.base, tr.length) == NULL) return (DNS_R_NOSPACE); isc_buffer_add(target, strlen(tr.base)); isc_region_consume(&sr, 4); diff --git a/lib/dns/redblack.c b/lib/dns/redblack.c index bafef56509..878602f85a 100644 --- a/lib/dns/redblack.c +++ b/lib/dns/redblack.c @@ -15,10 +15,11 @@ * SOFTWARE. */ +#include + #include #include #include -#include #include #include diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index e5adf36555..d0d02d83d0 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -14,7 +14,8 @@ CWARNINGS = OBJS = assertions.o buffer.o error.o heap.o lex.o mem.o result.o \ rwlock.o symtab.o task.o timer.o version.o \ unix/time.o unix/socket.o \ - pthreads/condition.o + pthreads/condition.o \ + @ISC_EXTRA_OBJS@ SUBDIRS = include unix pthreads TARGETS = timestamp diff --git a/lib/isc/include/isc/inet.h b/lib/isc/include/isc/inet.h new file mode 100644 index 0000000000..9fc277af33 --- /dev/null +++ b/lib/isc/include/isc/inet.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifndef ISC_INET_H +#define ISC_INET_H 1 + +/* + * Provide missing functionality that functions internal to the isc/dns + * library will need. + * + * This file will need to be generated if it will be installed, since it + * depends on being included. This won't work outside our + * controlled tree. + */ + +#ifdef NEED_INET_NTOP +char *isc_inet_ntop(int af, const void *src, char *dst, size_t size); +#else +#define isc_inet_ntop inet_ntop +#endif + +#endif /* ISC_INET_H */ diff --git a/lib/isc/inet_ntop.c b/lib/isc/inet_ntop.c new file mode 100644 index 0000000000..c1fc07af4f --- /dev/null +++ b/lib/isc/inet_ntop.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 1996-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char rcsid[] = "$Id: inet_ntop.c,v 1.1 1999/01/22 04:35:11 explorer Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#define NS_INT16SZ 2 +#define NS_IN6ADDRSZ 16 + +/* + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ + +static const char *isc_inet_ntop4(const u_char *src, char *dst, size_t size); +static const char *isc_inet_ntop6(const u_char *src, char *dst, size_t size); + +/* char * + * isc_inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + * author: + * Paul Vixie, 1996. + */ +const char * +isc_inet_ntop(int af, const void *src, char *dst, size_t size) +{ + switch (af) { + case AF_INET: + return (isc_inet_ntop4(src, dst, size)); + case AF_INET6: + return (isc_inet_ntop6(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (NULL); + } + /* NOTREACHED */ +} + +/* const char * + * isc_inet_ntop4(src, dst, size) + * format an IPv4 address + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a u_char* not an in_addr as input + * author: + * Paul Vixie, 1996. + */ +static const char * +isc_inet_ntop4(const u_char *src, char *dst, size_t size) +{ + static const char *fmt = "%u.%u.%u.%u"; + char tmp[sizeof "255.255.255.255"]; + + if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { + errno = ENOSPC; + return (NULL); + } + strcpy(dst, tmp); + + return (dst); +} + +/* const char * + * isc_inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + * author: + * Paul Vixie, 1996. + */ +static const char * +isc_inet_ntop6(const u_char *src, char *dst, size_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + struct { int base, len; } best, cur; + u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i++) + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); + best.base = -1; + cur.base = -1; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + if (words[i] == 0) { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + if (!isc_inet_ntop4(src+12, tp, + sizeof tmp - (tp - tmp))) + return (NULL); + tp += strlen(tp); + break; + } + tp += sprintf(tp, "%x", words[i]); + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((size_t)(tp - tmp) > size) { + errno = ENOSPC; + return (NULL); + } + strcpy(dst, tmp); + return (dst); +} -- GitLab