Blame resolv/nss_dns/dns-network.c

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* Parts of this file are plain copies of the file `getnetnamadr.c' from
Packit 6c4009
   the bind package and it has the following copyright.  */
Packit 6c4009
Packit 6c4009
/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
Packit 6c4009
 *      Dep. Matematica Universidade de Coimbra, Portugal, Europe
Packit 6c4009
 *
Packit 6c4009
 * Permission to use, copy, modify, and distribute this software for any
Packit 6c4009
 * purpose with or without fee is hereby granted, provided that the above
Packit 6c4009
 * copyright notice and this permission notice appear in all copies.
Packit 6c4009
 */
Packit 6c4009
/*
Packit 6c4009
 * Copyright (c) 1983, 1993
Packit 6c4009
 *      The Regents of the University of California.  All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Redistribution and use in source and binary forms, with or without
Packit 6c4009
 * modification, are permitted provided that the following conditions
Packit 6c4009
 * are met:
Packit 6c4009
 * 1. Redistributions of source code must retain the above copyright
Packit 6c4009
 *    notice, this list of conditions and the following disclaimer.
Packit 6c4009
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 6c4009
 *    notice, this list of conditions and the following disclaimer in the
Packit 6c4009
 *    documentation and/or other materials provided with the distribution.
Packit 6c4009
 * 4. Neither the name of the University nor the names of its contributors
Packit 6c4009
 *    may be used to endorse or promote products derived from this software
Packit 6c4009
 *    without specific prior written permission.
Packit 6c4009
 *
Packit 6c4009
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 6c4009
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 6c4009
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 6c4009
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 6c4009
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 6c4009
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 6c4009
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 6c4009
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 6c4009
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 6c4009
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 6c4009
 * SUCH DAMAGE.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <ctype.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <netdb.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <stddef.h>
Packit 6c4009
Packit 6c4009
#include "nsswitch.h"
Packit 6c4009
#include <arpa/inet.h>
Packit 6c4009
#include <arpa/nameser.h>
Packit 6c4009
#include <resolv/resolv-internal.h>
Packit 6c4009
#include <resolv/resolv_context.h>
Packit 6c4009
Packit 6c4009
/* Maximum number of aliases we allow.  */
Packit 6c4009
#define MAX_NR_ALIASES	48
Packit 6c4009
Packit 6c4009
Packit 6c4009
#if PACKETSZ > 65536
Packit 6c4009
# define MAXPACKET	PACKETSZ
Packit 6c4009
#else
Packit 6c4009
# define MAXPACKET	65536
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
typedef enum
Packit 6c4009
{
Packit 6c4009
  BYADDR,
Packit 6c4009
  BYNAME
Packit 6c4009
} lookup_method;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* We need this time later.  */
Packit 6c4009
typedef union querybuf
Packit 6c4009
{
Packit 6c4009
  HEADER hdr;
Packit 6c4009
  u_char buf[MAXPACKET];
Packit 6c4009
} querybuf;
Packit 6c4009
Packit 6c4009
/* Prototypes for local functions.  */
Packit 6c4009
static enum nss_status getanswer_r (const querybuf *answer, int anslen,
Packit 6c4009
				    struct netent *result, char *buffer,
Packit 6c4009
				    size_t buflen, int *errnop, int *h_errnop,
Packit 6c4009
				    lookup_method net_i);
Packit 6c4009
Packit 6c4009
Packit 6c4009
enum nss_status
Packit 6c4009
_nss_dns_getnetbyname_r (const char *name, struct netent *result,
Packit 6c4009
			 char *buffer, size_t buflen, int *errnop,
Packit 6c4009
			 int *herrnop)
Packit 6c4009
{
Packit 6c4009
  /* Return entry for network with NAME.  */
Packit 6c4009
  union
Packit 6c4009
  {
Packit 6c4009
    querybuf *buf;
Packit 6c4009
    u_char *ptr;
Packit 6c4009
  } net_buffer;
Packit 6c4009
  querybuf *orig_net_buffer;
Packit 6c4009
  int anslen;
Packit 6c4009
  enum nss_status status;
Packit 6c4009
Packit 6c4009
  struct resolv_context *ctx = __resolv_context_get ();
Packit 6c4009
  if (ctx == NULL)
Packit 6c4009
    {
Packit 6c4009
      *errnop = errno;
Packit 6c4009
      *herrnop = NETDB_INTERNAL;
Packit 6c4009
      return NSS_STATUS_UNAVAIL;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
Packit 6c4009
Packit 6c4009
  anslen = __res_context_search
Packit 6c4009
    (ctx, name, C_IN, T_PTR, net_buffer.buf->buf,
Packit 6c4009
     1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
Packit 6c4009
  if (anslen < 0)
Packit 6c4009
    {
Packit 6c4009
      /* Nothing found.  */
Packit 6c4009
      *errnop = errno;
Packit 6c4009
      if (net_buffer.buf != orig_net_buffer)
Packit 6c4009
	free (net_buffer.buf);
Packit 6c4009
      __resolv_context_put (ctx);
Packit 6c4009
      return (errno == ECONNREFUSED
Packit 6c4009
	      || errno == EPFNOSUPPORT
Packit 6c4009
	      || errno == EAFNOSUPPORT)
Packit 6c4009
	? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen,
Packit 6c4009
			errnop, herrnop, BYNAME);
Packit 6c4009
  if (net_buffer.buf != orig_net_buffer)
Packit 6c4009
    free (net_buffer.buf);
Packit 6c4009
  __resolv_context_put (ctx);
Packit 6c4009
  return status;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
enum nss_status
Packit 6c4009
_nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
Packit 6c4009
			 char *buffer, size_t buflen, int *errnop,
Packit 6c4009
			 int *herrnop)
Packit 6c4009
{
Packit 6c4009
  /* Return entry for network with NAME.  */
Packit 6c4009
  enum nss_status status;
Packit 6c4009
  union
Packit 6c4009
  {
Packit 6c4009
    querybuf *buf;
Packit 6c4009
    u_char *ptr;
Packit 6c4009
  } net_buffer;
Packit 6c4009
  querybuf *orig_net_buffer;
Packit 6c4009
  unsigned int net_bytes[4];
Packit 6c4009
  char qbuf[MAXDNAME];
Packit 6c4009
  int cnt, anslen;
Packit 6c4009
  uint32_t net2;
Packit 6c4009
  int olderr = errno;
Packit 6c4009
Packit 6c4009
  /* No net address lookup for IPv6 yet.  */
Packit 6c4009
  if (type != AF_INET)
Packit 6c4009
    return NSS_STATUS_UNAVAIL;
Packit 6c4009
Packit 6c4009
  struct resolv_context *ctx = __resolv_context_get ();
Packit 6c4009
  if (ctx == NULL)
Packit 6c4009
    {
Packit 6c4009
      *errnop = errno;
Packit 6c4009
      *herrnop = NETDB_INTERNAL;
Packit 6c4009
      return NSS_STATUS_UNAVAIL;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  net2 = (uint32_t) net;
Packit 6c4009
  for (cnt = 4; net2 != 0; net2 >>= 8)
Packit 6c4009
    net_bytes[--cnt] = net2 & 0xff;
Packit 6c4009
Packit 6c4009
  switch (cnt)
Packit 6c4009
    {
Packit 6c4009
    case 3:
Packit 6c4009
      /* Class A network.  */
Packit 6c4009
      sprintf (qbuf, "0.0.0.%u.in-addr.arpa", net_bytes[3]);
Packit 6c4009
      break;
Packit 6c4009
    case 2:
Packit 6c4009
      /* Class B network.  */
Packit 6c4009
      sprintf (qbuf, "0.0.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2]);
Packit 6c4009
      break;
Packit 6c4009
    case 1:
Packit 6c4009
      /* Class C network.  */
Packit 6c4009
      sprintf (qbuf, "0.%u.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2],
Packit 6c4009
	       net_bytes[1]);
Packit 6c4009
      break;
Packit 6c4009
    case 0:
Packit 6c4009
      /* Class D - E network.  */
Packit 6c4009
      sprintf (qbuf, "%u.%u.%u.%u.in-addr.arpa", net_bytes[3], net_bytes[2],
Packit 6c4009
	       net_bytes[1], net_bytes[0]);
Packit 6c4009
      break;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
Packit 6c4009
Packit 6c4009
  anslen = __res_context_query (ctx, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
Packit 6c4009
				1024, &net_buffer.ptr, NULL, NULL, NULL, NULL);
Packit 6c4009
  if (anslen < 0)
Packit 6c4009
    {
Packit 6c4009
      /* Nothing found.  */
Packit 6c4009
      int err = errno;
Packit 6c4009
      __set_errno (olderr);
Packit 6c4009
      if (net_buffer.buf != orig_net_buffer)
Packit 6c4009
	free (net_buffer.buf);
Packit 6c4009
      __resolv_context_put (ctx);
Packit 6c4009
      return (err == ECONNREFUSED
Packit 6c4009
	      || err == EPFNOSUPPORT
Packit 6c4009
	      || err == EAFNOSUPPORT)
Packit 6c4009
	? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen,
Packit 6c4009
			errnop, herrnop, BYADDR);
Packit 6c4009
  if (net_buffer.buf != orig_net_buffer)
Packit 6c4009
    free (net_buffer.buf);
Packit 6c4009
  if (status == NSS_STATUS_SUCCESS)
Packit 6c4009
    {
Packit 6c4009
      /* Strip trailing zeros.  */
Packit 6c4009
      unsigned int u_net = net;	/* Maybe net should be unsigned?  */
Packit 6c4009
Packit 6c4009
      while ((u_net & 0xff) == 0 && u_net != 0)
Packit 6c4009
	u_net >>= 8;
Packit 6c4009
      result->n_net = u_net;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  __resolv_context_put (ctx);
Packit 6c4009
  return status;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static enum nss_status
Packit 6c4009
getanswer_r (const querybuf *answer, int anslen, struct netent *result,
Packit 6c4009
	     char *buffer, size_t buflen, int *errnop, int *h_errnop,
Packit 6c4009
	     lookup_method net_i)
Packit 6c4009
{
Packit 6c4009
  /*
Packit 6c4009
   * Find first satisfactory answer
Packit 6c4009
   *
Packit 6c4009
   *      answer --> +------------+  ( MESSAGE )
Packit 6c4009
   *                 |   Header   |
Packit 6c4009
   *                 +------------+
Packit 6c4009
   *                 |  Question  | the question for the name server
Packit 6c4009
   *                 +------------+
Packit 6c4009
   *                 |   Answer   | RRs answering the question
Packit 6c4009
   *                 +------------+
Packit 6c4009
   *                 | Authority  | RRs pointing toward an authority
Packit 6c4009
   *                 | Additional | RRs holding additional information
Packit 6c4009
   *                 +------------+
Packit 6c4009
   */
Packit 6c4009
  struct net_data
Packit 6c4009
  {
Packit 6c4009
    char *aliases[MAX_NR_ALIASES];
Packit 6c4009
    char linebuffer[0];
Packit 6c4009
  } *net_data;
Packit 6c4009
Packit 6c4009
  uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct net_data);
Packit 6c4009
  buffer += pad;
Packit 6c4009
Packit 6c4009
  if (__glibc_unlikely (buflen < sizeof (*net_data) + pad))
Packit 6c4009
    {
Packit 6c4009
      /* The buffer is too small.  */
Packit 6c4009
    too_small:
Packit 6c4009
      *errnop = ERANGE;
Packit 6c4009
      *h_errnop = NETDB_INTERNAL;
Packit 6c4009
      return NSS_STATUS_TRYAGAIN;
Packit 6c4009
    }
Packit 6c4009
  buflen -= pad;
Packit 6c4009
Packit 6c4009
  net_data = (struct net_data *) buffer;
Packit 6c4009
  int linebuflen = buflen - offsetof (struct net_data, linebuffer);
Packit 6c4009
  if (buflen - offsetof (struct net_data, linebuffer) != linebuflen)
Packit 6c4009
    linebuflen = INT_MAX;
Packit 6c4009
  const unsigned char *end_of_message = &answer->buf[anslen];
Packit 6c4009
  const HEADER *header_pointer = &answer->hdr;
Packit 6c4009
  /* #/records in the answer section.  */
Packit 6c4009
  int answer_count =  ntohs (header_pointer->ancount);
Packit 6c4009
  /* #/entries in the question section.  */
Packit 6c4009
  int question_count = ntohs (header_pointer->qdcount);
Packit 6c4009
  char *bp = net_data->linebuffer;
Packit 6c4009
  const unsigned char *cp = &answer->buf[HFIXEDSZ];
Packit 6c4009
  char **alias_pointer;
Packit 6c4009
  int have_answer;
Packit 6c4009
  u_char packtmp[NS_MAXCDNAME];
Packit 6c4009
Packit 6c4009
  if (question_count == 0)
Packit 6c4009
    {
Packit 6c4009
      /* FIXME: the Sun version uses for host name lookup an additional
Packit 6c4009
	 parameter for pointing to h_errno.  this is missing here.
Packit 6c4009
	 OSF/1 has a per-thread h_errno variable.  */
Packit 6c4009
      if (header_pointer->aa != 0)
Packit 6c4009
	{
Packit 6c4009
	  __set_h_errno (HOST_NOT_FOUND);
Packit 6c4009
	  return NSS_STATUS_NOTFOUND;
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  __set_h_errno (TRY_AGAIN);
Packit 6c4009
	  return NSS_STATUS_TRYAGAIN;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Skip the question part.  */
Packit 6c4009
  while (question_count-- > 0)
Packit 6c4009
    {
Packit 6c4009
      int n = __dn_skipname (cp, end_of_message);
Packit 6c4009
      if (n < 0 || end_of_message - (cp + n) < QFIXEDSZ)
Packit 6c4009
       {
Packit 6c4009
         __set_h_errno (NO_RECOVERY);
Packit 6c4009
         return NSS_STATUS_UNAVAIL;
Packit 6c4009
       }
Packit 6c4009
      cp += n + QFIXEDSZ;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  alias_pointer = result->n_aliases = &net_data->aliases[0];
Packit 6c4009
  *alias_pointer = NULL;
Packit 6c4009
  have_answer = 0;
Packit 6c4009
Packit 6c4009
  while (--answer_count >= 0 && cp < end_of_message)
Packit 6c4009
    {
Packit 6c4009
      int n = __ns_name_unpack (answer->buf, end_of_message, cp,
Packit 6c4009
				packtmp, sizeof packtmp);
Packit 6c4009
      if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
Packit 6c4009
	{
Packit 6c4009
	  if (errno == EMSGSIZE)
Packit 6c4009
	    goto too_small;
Packit 6c4009
Packit 6c4009
	  n = -1;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      if (n > 0 && bp[0] == '.')
Packit 6c4009
	bp[0] = '\0';
Packit 6c4009
Packit 6c4009
      if (n < 0 || res_dnok (bp) == 0)
Packit 6c4009
	break;
Packit 6c4009
      cp += n;
Packit 6c4009
Packit 6c4009
      if (end_of_message - cp < 10)
Packit 6c4009
	{
Packit 6c4009
	  __set_h_errno (NO_RECOVERY);
Packit 6c4009
	  return NSS_STATUS_UNAVAIL;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      int type, class;
Packit 6c4009
      GETSHORT (type, cp);
Packit 6c4009
      GETSHORT (class, cp);
Packit 6c4009
      cp += INT32SZ;		/* TTL */
Packit 6c4009
      uint16_t rdatalen;
Packit 6c4009
      GETSHORT (rdatalen, cp);
Packit 6c4009
      if (end_of_message - cp < rdatalen)
Packit 6c4009
	{
Packit 6c4009
	  __set_h_errno (NO_RECOVERY);
Packit 6c4009
	  return NSS_STATUS_UNAVAIL;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      if (class == C_IN && type == T_PTR)
Packit 6c4009
	{
Packit 6c4009
	  n = __ns_name_unpack (answer->buf, end_of_message, cp,
Packit 6c4009
				packtmp, sizeof packtmp);
Packit 6c4009
	  if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
Packit 6c4009
	    {
Packit 6c4009
	      if (errno == EMSGSIZE)
Packit 6c4009
		goto too_small;
Packit 6c4009
Packit 6c4009
	      n = -1;
Packit 6c4009
	    }
Packit 6c4009
Packit 6c4009
	  if (n < 0 || !res_hnok (bp))
Packit 6c4009
	    {
Packit 6c4009
	      /* XXX What does this mean?  The original form from bind
Packit 6c4009
		 returns NULL. Incrementing cp has no effect in any case.
Packit 6c4009
		 What should I return here. ??? */
Packit 6c4009
	      cp += n;
Packit 6c4009
	      return NSS_STATUS_UNAVAIL;
Packit 6c4009
	    }
Packit 6c4009
	  cp += rdatalen;
Packit 6c4009
         if (alias_pointer + 2 < &net_data->aliases[MAX_NR_ALIASES])
Packit 6c4009
           {
Packit 6c4009
             *alias_pointer++ = bp;
Packit 6c4009
             n = strlen (bp) + 1;
Packit 6c4009
             bp += n;
Packit 6c4009
             linebuflen -= n;
Packit 6c4009
             result->n_addrtype = class == C_IN ? AF_INET : AF_UNSPEC;
Packit 6c4009
             ++have_answer;
Packit 6c4009
           }
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	/* Skip over unknown record data.  */
Packit 6c4009
	cp += rdatalen;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (have_answer)
Packit 6c4009
    {
Packit 6c4009
      *alias_pointer = NULL;
Packit 6c4009
      switch (net_i)
Packit 6c4009
	{
Packit 6c4009
	case BYADDR:
Packit 6c4009
	  result->n_name = *result->n_aliases++;
Packit 6c4009
	  result->n_net = 0L;
Packit 6c4009
	  return NSS_STATUS_SUCCESS;
Packit 6c4009
Packit 6c4009
	case BYNAME:
Packit 6c4009
	  {
Packit 6c4009
	    char **ap;
Packit 6c4009
	    for (ap = result->n_aliases; *ap != NULL; ++ap)
Packit 6c4009
	      {
Packit 6c4009
		/* Check each alias name for being of the forms:
Packit 6c4009
		   4.3.2.1.in-addr.arpa		= net 1.2.3.4
Packit 6c4009
		   3.2.1.in-addr.arpa		= net 0.1.2.3
Packit 6c4009
		   2.1.in-addr.arpa		= net 0.0.1.2
Packit 6c4009
		   1.in-addr.arpa		= net 0.0.0.1
Packit 6c4009
		*/
Packit 6c4009
		uint32_t val = 0;	/* Accumulator for n_net value.  */
Packit 6c4009
		unsigned int shift = 0; /* Which part we are parsing now.  */
Packit 6c4009
		const char *p = *ap; /* Consuming the string.  */
Packit 6c4009
		do
Packit 6c4009
		  {
Packit 6c4009
		    /* Match the leading 0 or 0[xX] base indicator.  */
Packit 6c4009
		    unsigned int base = 10;
Packit 6c4009
		    if (*p == '0' && p[1] != '.')
Packit 6c4009
		      {
Packit 6c4009
			base = 8;
Packit 6c4009
			++p;
Packit 6c4009
			if (*p == 'x' || *p == 'X')
Packit 6c4009
			  {
Packit 6c4009
			    base = 16;
Packit 6c4009
			    ++p;
Packit 6c4009
			    if (*p == '.')
Packit 6c4009
			      break; /* No digit here.  Give up on alias.  */
Packit 6c4009
			  }
Packit 6c4009
			if (*p == '\0')
Packit 6c4009
			  break;
Packit 6c4009
		      }
Packit 6c4009
Packit 6c4009
		    uint32_t part = 0; /* Accumulates this part's number.  */
Packit 6c4009
		    do
Packit 6c4009
		      {
Packit 6c4009
			if (isdigit (*p) && (*p - '0' < base))
Packit 6c4009
			  part = (part * base) + (*p - '0');
Packit 6c4009
			else if (base == 16 && isxdigit (*p))
Packit 6c4009
			  part = (part << 4) + 10 + (tolower (*p) - 'a');
Packit 6c4009
			++p;
Packit 6c4009
		      } while (*p != '\0' && *p != '.');
Packit 6c4009
Packit 6c4009
		    if (*p != '.')
Packit 6c4009
		      break;	/* Bad form.  Give up on this name.  */
Packit 6c4009
Packit 6c4009
		    /* Install this as the next more significant byte.  */
Packit 6c4009
		    val |= part << shift;
Packit 6c4009
		    shift += 8;
Packit 6c4009
		    ++p;
Packit 6c4009
Packit 6c4009
		    /* If we are out of digits now, there are two cases:
Packit 6c4009
		       1. We are done with digits and now see "in-addr.arpa".
Packit 6c4009
		       2. This is not the droid we are looking for.  */
Packit 6c4009
		    if (!isdigit (*p) && !strcasecmp (p, "in-addr.arpa"))
Packit 6c4009
		      {
Packit 6c4009
			result->n_net = val;
Packit 6c4009
			return NSS_STATUS_SUCCESS;
Packit 6c4009
		      }
Packit 6c4009
Packit 6c4009
		    /* Keep going when we have seen fewer than 4 parts.  */
Packit 6c4009
		  } while (shift < 32);
Packit 6c4009
	      }
Packit 6c4009
	  }
Packit 6c4009
	  break;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  __set_h_errno (TRY_AGAIN);
Packit 6c4009
  return NSS_STATUS_TRYAGAIN;
Packit 6c4009
}