mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
Add isc_inet_aton() and a check to use system inet_aton()
This commit is contained in:
parent
70db22e93b
commit
c810fcbf6c
63
configure
vendored
63
configure
vendored
@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
# From configure.in Revision: 1.9
|
# From configure.in Revision: 1.10
|
||||||
|
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated automatically using autoconf version 2.12
|
# Generated automatically using autoconf version 2.12
|
||||||
@ -1421,11 +1421,66 @@ ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS inet_ntop.o"
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $ac_n "checking for inet_aton""... $ac_c" 1>&6
|
||||||
|
echo "configure:1428: checking for inet_aton" >&5
|
||||||
|
if eval "test \"`echo '$''{'ac_cv_func_inet_aton'+set}'`\" = set"; then
|
||||||
|
echo $ac_n "(cached) $ac_c" 1>&6
|
||||||
|
else
|
||||||
|
cat > conftest.$ac_ext <<EOF
|
||||||
|
#line 1433 "configure"
|
||||||
|
#include "confdefs.h"
|
||||||
|
/* System header to define __stub macros and hopefully few prototypes,
|
||||||
|
which can conflict with char inet_aton(); below. */
|
||||||
|
#include <assert.h>
|
||||||
|
/* 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_aton();
|
||||||
|
|
||||||
|
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_aton) || defined (__stub___inet_aton)
|
||||||
|
choke me
|
||||||
|
#else
|
||||||
|
inet_aton();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
; return 0; }
|
||||||
|
EOF
|
||||||
|
if { (eval echo configure:1456: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
|
||||||
|
rm -rf conftest*
|
||||||
|
eval "ac_cv_func_inet_aton=yes"
|
||||||
|
else
|
||||||
|
echo "configure: failed program was:" >&5
|
||||||
|
cat conftest.$ac_ext >&5
|
||||||
|
rm -rf conftest*
|
||||||
|
eval "ac_cv_func_inet_aton=no"
|
||||||
|
fi
|
||||||
|
rm -f conftest*
|
||||||
|
fi
|
||||||
|
|
||||||
|
if eval "test \"`echo '$ac_cv_func_'inet_aton`\" = yes"; then
|
||||||
|
echo "$ac_t""yes" 1>&6
|
||||||
|
:
|
||||||
|
else
|
||||||
|
echo "$ac_t""no" 1>&6
|
||||||
|
ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS inet_aton.o"
|
||||||
|
|
||||||
|
cat >> confdefs.h <<\EOF
|
||||||
|
#define NEED_INET_ATON 1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
|
echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
|
||||||
echo "configure:1429: checking whether ${MAKE-make} sets \${MAKE}" >&5
|
echo "configure:1484: checking whether ${MAKE-make} sets \${MAKE}" >&5
|
||||||
set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
|
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
|
if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
|
||||||
echo $ac_n "(cached) $ac_c" 1>&6
|
echo $ac_n "(cached) $ac_c" 1>&6
|
||||||
@ -1454,7 +1509,7 @@ fi
|
|||||||
# Extract the first word of "ranlib", so it can be a program name with args.
|
# Extract the first word of "ranlib", so it can be a program name with args.
|
||||||
set dummy ranlib; ac_word=$2
|
set dummy ranlib; ac_word=$2
|
||||||
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
||||||
echo "configure:1458: checking for $ac_word" >&5
|
echo "configure:1513: checking for $ac_word" >&5
|
||||||
if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
|
if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
|
||||||
echo $ac_n "(cached) $ac_c" 1>&6
|
echo $ac_n "(cached) $ac_c" 1>&6
|
||||||
else
|
else
|
||||||
@ -1491,7 +1546,7 @@ fi
|
|||||||
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
|
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
|
||||||
# ./install, which can be erroneously created by make from ./install.sh.
|
# ./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 $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
|
||||||
echo "configure:1495: checking for a BSD compatible install" >&5
|
echo "configure:1550: checking for a BSD compatible install" >&5
|
||||||
if test -z "$INSTALL"; then
|
if test -z "$INSTALL"; then
|
||||||
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
|
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
|
||||||
echo $ac_n "(cached) $ac_c" 1>&6
|
echo $ac_n "(cached) $ac_c" 1>&6
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
AC_REVISION($Revision: 1.10 $)
|
AC_REVISION($Revision: 1.11 $)
|
||||||
|
|
||||||
AC_INIT(lib/dns/name.c)
|
AC_INIT(lib/dns/name.c)
|
||||||
AC_CONFIG_HEADER(config.h)
|
AC_CONFIG_HEADER(config.h)
|
||||||
@ -29,6 +29,11 @@ AC_CHECK_FUNC(inet_ntop, ,
|
|||||||
AC_SUBST(ISC_EXTRA_OBJS)
|
AC_SUBST(ISC_EXTRA_OBJS)
|
||||||
AC_DEFINE(NEED_INET_NTOP)]
|
AC_DEFINE(NEED_INET_NTOP)]
|
||||||
)
|
)
|
||||||
|
AC_CHECK_FUNC(inet_aton, ,
|
||||||
|
[ISC_EXTRA_OBJS="$ISC_EXTRA_OBJS inet_aton.o"
|
||||||
|
AC_SUBST(ISC_EXTRA_OBJS)
|
||||||
|
AC_DEFINE(NEED_INET_ATON)]
|
||||||
|
)
|
||||||
|
|
||||||
AC_PROG_MAKE_SET
|
AC_PROG_MAKE_SET
|
||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: a_1.c,v 1.8 1999/01/22 05:02:49 marka Exp $ */
|
/* $Id: a_1.c,v 1.9 1999/01/30 04:27:47 explorer Exp $ */
|
||||||
|
|
||||||
#ifndef RDATA_IN_1_A_1_H
|
#ifndef RDATA_IN_1_A_1_H
|
||||||
#define RDATA_IN_1_A_1_H
|
#define RDATA_IN_1_A_1_H
|
||||||
@ -46,7 +46,7 @@ fromtext_in_a(dns_rdataclass_t class, dns_rdatatype_t type,
|
|||||||
|
|
||||||
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
||||||
|
|
||||||
if (inet_aton(token.value.as_pointer , &addr) != 1)
|
if (isc_inet_aton(token.value.as_pointer, &addr) != 1)
|
||||||
return (DNS_R_UNEXPECTED);
|
return (DNS_R_UNEXPECTED);
|
||||||
isc_buffer_available(target, ®ion);
|
isc_buffer_available(target, ®ion);
|
||||||
if (region.length < 4)
|
if (region.length < 4)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: a_1.h,v 1.8 1999/01/22 05:02:49 marka Exp $ */
|
/* $Id: a_1.h,v 1.9 1999/01/30 04:27:47 explorer Exp $ */
|
||||||
|
|
||||||
#ifndef RDATA_IN_1_A_1_H
|
#ifndef RDATA_IN_1_A_1_H
|
||||||
#define RDATA_IN_1_A_1_H
|
#define RDATA_IN_1_A_1_H
|
||||||
@ -46,7 +46,7 @@ fromtext_in_a(dns_rdataclass_t class, dns_rdatatype_t type,
|
|||||||
|
|
||||||
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
||||||
|
|
||||||
if (inet_aton(token.value.as_pointer , &addr) != 1)
|
if (isc_inet_aton(token.value.as_pointer, &addr) != 1)
|
||||||
return (DNS_R_UNEXPECTED);
|
return (DNS_R_UNEXPECTED);
|
||||||
isc_buffer_available(target, ®ion);
|
isc_buffer_available(target, ®ion);
|
||||||
if (region.length < 4)
|
if (region.length < 4)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: wks_11.c,v 1.4 1999/01/22 05:02:49 marka Exp $ */
|
/* $Id: wks_11.c,v 1.5 1999/01/30 04:27:47 explorer Exp $ */
|
||||||
|
|
||||||
#ifndef RDATA_IN_1_WKS_11_H
|
#ifndef RDATA_IN_1_WKS_11_H
|
||||||
#define RDATA_IN_1_WKS_11_H
|
#define RDATA_IN_1_WKS_11_H
|
||||||
@ -59,7 +59,7 @@ fromtext_in_wks(dns_rdataclass_t class, dns_rdatatype_t type,
|
|||||||
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
||||||
|
|
||||||
isc_buffer_available(target, ®ion);
|
isc_buffer_available(target, ®ion);
|
||||||
if (inet_aton(token.value.as_pointer , &addr) != 1)
|
if (isc_inet_aton(token.value.as_pointer, &addr) != 1)
|
||||||
return (DNS_R_BADDOTTEDQUAD);
|
return (DNS_R_BADDOTTEDQUAD);
|
||||||
if (region.length < 4)
|
if (region.length < 4)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: wks_11.h,v 1.4 1999/01/22 05:02:49 marka Exp $ */
|
/* $Id: wks_11.h,v 1.5 1999/01/30 04:27:47 explorer Exp $ */
|
||||||
|
|
||||||
#ifndef RDATA_IN_1_WKS_11_H
|
#ifndef RDATA_IN_1_WKS_11_H
|
||||||
#define RDATA_IN_1_WKS_11_H
|
#define RDATA_IN_1_WKS_11_H
|
||||||
@ -59,7 +59,7 @@ fromtext_in_wks(dns_rdataclass_t class, dns_rdatatype_t type,
|
|||||||
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
|
||||||
|
|
||||||
isc_buffer_available(target, ®ion);
|
isc_buffer_available(target, ®ion);
|
||||||
if (inet_aton(token.value.as_pointer , &addr) != 1)
|
if (isc_inet_aton(token.value.as_pointer, &addr) != 1)
|
||||||
return (DNS_R_BADDOTTEDQUAD);
|
return (DNS_R_BADDOTTEDQUAD);
|
||||||
if (region.length < 4)
|
if (region.length < 4)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
|
@ -33,4 +33,10 @@ char *isc_inet_ntop(int af, const void *src, char *dst, size_t size);
|
|||||||
#define isc_inet_ntop inet_ntop
|
#define isc_inet_ntop inet_ntop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef NEED_INET_ATON
|
||||||
|
int isc_inet_aton(const char *cp, struct in_addr *addr);
|
||||||
|
#else
|
||||||
|
#define isc_inet_aton inet_aton
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ISC_INET_H */
|
#endif /* ISC_INET_H */
|
||||||
|
192
lib/isc/inet_aton.c
Normal file
192
lib/isc/inet_aton.c
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* 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, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions 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 sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
|
||||||
|
static char rcsid[] = "$Id: inet_aton.c,v 1.1 1999/01/30 04:27:48 explorer Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include <isc/types.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check whether "cp" is a valid ascii representation
|
||||||
|
* of an Internet address and convert to a binary address.
|
||||||
|
* Returns 1 if the address is valid, 0 if not.
|
||||||
|
* This replaces inet_addr, the return value from which
|
||||||
|
* cannot distinguish between failure and a local broadcast address.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
inet_aton(const char *cp, struct in_addr *addr)
|
||||||
|
{
|
||||||
|
unsigned long val;
|
||||||
|
int base, n;
|
||||||
|
char c;
|
||||||
|
isc_uint8_t parts[4];
|
||||||
|
isc_uint8_t *pp = parts;
|
||||||
|
int digit;
|
||||||
|
|
||||||
|
c = *cp;
|
||||||
|
for (;;) {
|
||||||
|
/*
|
||||||
|
* Collect number up to ``.''.
|
||||||
|
* Values are specified as for C:
|
||||||
|
* 0x=hex, 0=octal, isdigit=decimal.
|
||||||
|
*/
|
||||||
|
if (!isdigit(c))
|
||||||
|
return (0);
|
||||||
|
val = 0; base = 10; digit = 0;
|
||||||
|
if (c == '0') {
|
||||||
|
c = *++cp;
|
||||||
|
if (c == 'x' || c == 'X')
|
||||||
|
base = 16, c = *++cp;
|
||||||
|
else {
|
||||||
|
base = 8;
|
||||||
|
digit = 1 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (;;) {
|
||||||
|
if (isascii(c) && isdigit(c)) {
|
||||||
|
if (base == 8 && (c == '8' || c == '9'))
|
||||||
|
return (0);
|
||||||
|
val = (val * base) + (c - '0');
|
||||||
|
c = *++cp;
|
||||||
|
digit = 1;
|
||||||
|
} else if (base == 16 && isascii(c) && isxdigit(c)) {
|
||||||
|
val = (val << 4) |
|
||||||
|
(c + 10 - (islower(c) ? 'a' : 'A'));
|
||||||
|
c = *++cp;
|
||||||
|
digit = 1;
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c == '.') {
|
||||||
|
/*
|
||||||
|
* Internet format:
|
||||||
|
* a.b.c.d
|
||||||
|
* a.b.c (with c treated as 16 bits)
|
||||||
|
* a.b (with b treated as 24 bits)
|
||||||
|
*/
|
||||||
|
if (pp >= parts + 3 || val > 0xff)
|
||||||
|
return (0);
|
||||||
|
*pp++ = val;
|
||||||
|
c = *++cp;
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Check for trailing characters.
|
||||||
|
*/
|
||||||
|
if (c != '\0' && (!isascii(c) || !isspace(c)))
|
||||||
|
return (0);
|
||||||
|
/*
|
||||||
|
* Did we get a valid digit?
|
||||||
|
*/
|
||||||
|
if (!digit)
|
||||||
|
return (0);
|
||||||
|
/*
|
||||||
|
* Concoct the address according to
|
||||||
|
* the number of parts specified.
|
||||||
|
*/
|
||||||
|
n = pp - parts + 1;
|
||||||
|
switch (n) {
|
||||||
|
case 1: /* a -- 32 bits */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: /* a.b -- 8.24 bits */
|
||||||
|
if (val > 0xffffff)
|
||||||
|
return (0);
|
||||||
|
val |= parts[0] << 24;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: /* a.b.c -- 8.8.16 bits */
|
||||||
|
if (val > 0xffff)
|
||||||
|
return (0);
|
||||||
|
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||||
|
if (val > 0xff)
|
||||||
|
return (0);
|
||||||
|
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (addr != NULL)
|
||||||
|
addr->s_addr = htonl(val);
|
||||||
|
|
||||||
|
return (1);
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static char rcsid[] = "$Id: inet_ntop.c,v 1.1 1999/01/22 04:35:11 explorer Exp $";
|
static char rcsid[] = "$Id: inet_ntop.c,v 1.2 1999/01/30 04:27:48 explorer Exp $";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -40,7 +40,9 @@ static char rcsid[] = "$Id: inet_ntop.c,v 1.1 1999/01/22 04:35:11 explorer Exp $
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *isc_inet_ntop4(const u_char *src, char *dst, size_t size);
|
static const char *isc_inet_ntop4(const u_char *src, char *dst, size_t size);
|
||||||
|
#ifdef AF_INET6
|
||||||
static const char *isc_inet_ntop6(const u_char *src, char *dst, size_t size);
|
static const char *isc_inet_ntop6(const u_char *src, char *dst, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* char *
|
/* char *
|
||||||
* isc_inet_ntop(af, src, dst, size)
|
* isc_inet_ntop(af, src, dst, size)
|
||||||
@ -56,8 +58,10 @@ isc_inet_ntop(int af, const void *src, char *dst, size_t size)
|
|||||||
switch (af) {
|
switch (af) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return (isc_inet_ntop4(src, dst, size));
|
return (isc_inet_ntop4(src, dst, size));
|
||||||
|
#ifdef AF_INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return (isc_inet_ntop6(src, dst, size));
|
return (isc_inet_ntop6(src, dst, size));
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
errno = EAFNOSUPPORT;
|
errno = EAFNOSUPPORT;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -97,6 +101,7 @@ isc_inet_ntop4(const u_char *src, char *dst, size_t size)
|
|||||||
* author:
|
* author:
|
||||||
* Paul Vixie, 1996.
|
* Paul Vixie, 1996.
|
||||||
*/
|
*/
|
||||||
|
#ifdef AF_INET6
|
||||||
static const char *
|
static const char *
|
||||||
isc_inet_ntop6(const u_char *src, char *dst, size_t size)
|
isc_inet_ntop6(const u_char *src, char *dst, size_t size)
|
||||||
{
|
{
|
||||||
@ -185,3 +190,4 @@ isc_inet_ntop6(const u_char *src, char *dst, size_t size)
|
|||||||
strcpy(dst, tmp);
|
strcpy(dst, tmp);
|
||||||
return (dst);
|
return (dst);
|
||||||
}
|
}
|
||||||
|
#endif /* AF_INET6 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user