aboutsummaryrefslogtreecommitdiffstats
path: root/po
Commit message (Expand)AuthorAgeFilesLines
...
* Fix pluralization.Matthias Andree2005-04-271-786/+820
* Fix pluralization.Matthias Andree2005-04-272-236/+240
* Fix obvious typo (LSTMP -> LMTP).Matthias Andree2005-04-271-2/+2
* Update translationsMatthias Andree2005-04-262-819/+818
* Add Albanian translation.Matthias Andree2005-04-252-1/+2857
* Install updated translations from the translation project.Matthias Andree2005-04-162-633/+651
* Print warning if multidrop is configured, but not envelope option.Matthias Andree2005-04-131-153/+163
* Update translation for 'SSL is not enabled.'.Matthias Andree2005-03-191-14/+14
* Update.Matthias Andree2005-03-061-76/+94
* Remove bogus file.Matthias Andree2004-12-2710-6002/+4061
* Remove some unused cruft from the trunk.Graham Wilson2004-11-291-3/+0
* Add new help message(s). (Automatic:) Adjust line numbers.Matthias Andree2004-11-102-523/+545
* Update warning mail signature.Matthias Andree2004-10-203-265/+265
* chase xalloca.c removal.Matthias Andree2004-10-203-15/+12
* Delete obsolete file xalloca.c, now a macro.Matthias Andree2004-10-201-1/+0
* Fix fuzzy translations.Matthias Andree2004-10-201-340/+310
* Add xalloca.c translation for "alloca failed\n".Matthias Andree2004-10-201-374/+378
* Add xalloca.cMatthias Andree2004-10-201-0/+1
* Add translations for xalloca.c.Matthias Andree2004-10-201-1/+5
* Remove auto-generated file.Matthias Andree2004-10-201-2700/+0
* Remove pass-c-format, which is not documented clearly.Matthias Andree2004-10-201-2/+1
* Update msgid " %d msg %d octets long skipped by fetchmail."Matthias Andree2004-10-201-374/+374
* Disable outdated translations for now.Matthias Andree2004-10-201-1/+4
* Add some --flag to XGETTEXT_OPTIONS, to properly propagate c-format tag.Matthias Andree2004-10-201-1/+9
* Update.Matthias Andree2004-10-193-802/+708
* Update translation.Matthias Andree2004-08-201-403/+353
* Update .pot file after driver.c changes.Matthias Andree2004-08-201-358/+311
* Fix grammar in 'normal termination' message.Matthias Andree2004-08-081-1/+1
* This is the large automake/gettext commit.Matthias Andree2004-06-195-252/+42
* -3832/+3858
* Use yacc/bison source, not its outputRob Funk2004-06-181-1/+1
* List the input file rather than generated output.Matthias Andree2004-06-111-1/+1
* Remove .rej, .orig and .diff files that don't belong here.Matthias Andree2004-06-115-9523/+0
* Add files from ESR's dev directory that weren't under version controlRob Funk2004-06-0838-0/+51905
t .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 *  This file is part of libESMTP, a library for submission of RFC 2822
 *  formatted electronic mail messages using the SMTP protocol described
 *  in RFC 2821.
 *
 *  Copyright (C) 2001,2002  Brian Stafford  <brian@stafford.uklinux.net>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* An emulation of the RFC 2553 / Posix getaddrinfo resolver interface.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef HAVE_GETADDRINFO

/* Need to turn off Posix features in glibc to build this */
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <netdb.h>

#include "gethostbyname.h"
#include "getaddrinfo.h"

static struct addrinfo *
dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen)
{
  struct addrinfo *ret;

  ret = malloc (sizeof (struct addrinfo));
  if (ret == NULL)
    return NULL;
  memcpy (ret, info, sizeof (struct addrinfo));
  ret->ai_addr = malloc (addrlen);
  if (ret->ai_addr == NULL)
    {
      free (ret);
      return NULL;
    }
  memcpy (ret->ai_addr, addr, addrlen);
  ret->ai_addrlen = addrlen;
  return ret;
}

int
getaddrinfo (const char *nodename, const char *servname,
	     const struct addrinfo *hints, struct addrinfo **res)
{
  struct hostent *hp;
  struct servent *servent;
  const char *socktype;
  int port;
  struct addrinfo hint, result;
  struct addrinfo *ai, *sai, *eai;
  struct ghbnctx ghbnctx;
  char **addrs;
  int code;

  memset (&result, 0, sizeof result);

  /* default for hints */
  if (hints == NULL)
    {
      memset (&hint, 0, sizeof hint);
      hint.ai_family = PF_UNSPEC;
      hints = &hint;
    }

  if (servname == NULL && nodename == NULL)
    return EAI_NONAME;

  if (servname == NULL)
    port = 0;
  else {
    /* check for tcp or udp sockets only */
    if (hints->ai_socktype == SOCK_STREAM)
      socktype = "tcp";
    else if (hints->ai_socktype == SOCK_DGRAM)
      socktype = "udp";
    else
      return EAI_SERVICE;
    result.ai_socktype = hints->ai_socktype;

    /* Note: maintain port in host byte order to make debugging easier */
    if (isdigit (*servname))
      port = strtol (servname, NULL, 10);
    else if ((servent = getservbyname (servname, socktype)) != NULL)
      port = ntohs (servent->s_port);
    else
      return EAI_NONAME;
  }

  /* if nodename == NULL refer to the local host for a client or any
     for a server */
  if (nodename == NULL)
    {
      struct sockaddr_in sin;

      /* check protocol family is PF_UNSPEC or PF_INET - could try harder
         for IPv6 but that's more code than I'm prepared to write */
      if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
	result.ai_family = AF_INET;
      else
	return EAI_FAMILY;

      sin.sin_family = result.ai_family;
      sin.sin_port = htons (port);
      if (hints->ai_flags & AI_PASSIVE)
        sin.sin_addr.s_addr = htonl (INADDR_ANY);
      else
        sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
      /* Duplicate result and addr and return */
      *res = dup_addrinfo (&result, &sin, sizeof sin);
      return (*res == NULL) ? EAI_MEMORY : 0;
    }

  /* If AI_NUMERIC is specified, use inet_addr to translate numbers and
     dots notation. */
  if (hints->ai_flags & AI_NUMERICHOST)
    {
      struct sockaddr_in sin;

      /* check protocol family is PF_UNSPEC or PF_INET */
      if (hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET)
	result.ai_family = AF_INET;
      else
	return EAI_FAMILY;

      sin.sin_family = result.ai_family;
      sin.sin_port = htons (port);
      sin.sin_addr.s_addr = inet_addr (nodename);
      /* Duplicate result and addr and return */
      *res = dup_addrinfo (&result, &sin, sizeof sin);
      return (*res == NULL) ? EAI_MEMORY : 0;
    }

  errno = 0;
  hp = gethostbyname_ctx (nodename, &ghbnctx);
  if (hp == NULL)
    {
      if (errno != 0)
	{
	  free_ghbnctx (&ghbnctx);
	  return EAI_SYSTEM;
	}
      code = h_error_ctx (&ghbnctx);
      switch (code)
	{
	case HOST_NOT_FOUND: code = EAI_NODATA; break;
	case NO_DATA: code = EAI_NODATA; break;
#if defined(NO_ADDRESS) && NO_ADDRESS != NO_DATA
	case NO_ADDRESS: code = EAI_NODATA; break;
#endif
	case NO_RECOVERY: code = EAI_FAIL; break;
	case TRY_AGAIN: code = EAI_AGAIN; break;
	default: code = EAI_FAIL; break;
	}
      free_ghbnctx (&ghbnctx);
      return code;
    }

  /* Check that the address family is acceptable.
   */
  switch (hp->h_addrtype)
    {
    case AF_INET:
      if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET))
	goto eai_family;
      break;
#ifdef USE_IPV6
    case AF_INET6:
      if (!(hints->ai_family == PF_UNSPEC || hints->ai_family == PF_INET6))
	goto eai_family;
      break;
#endif
    default:
    eai_family:
      free_ghbnctx (&ghbnctx);
      return EAI_FAMILY;
    }

  /* For each element pointed to by hp, create an element in the
     result linked list. */
  sai = eai = NULL;
  for (addrs = hp->h_addr_list; *addrs != NULL; addrs++)
    {
      struct sockaddr sa;
      size_t addrlen;

      if (hp->h_length < 1)
        continue;
      sa.sa_family = hp->h_addrtype;
      switch (hp->h_addrtype)
        {
        case AF_INET:
	  ((struct sockaddr_in *) &sa)->sin_port = htons (port);
	  memcpy (&((struct sockaddr_in *) &sa)->sin_addr,
	          *addrs, hp->h_length);
          addrlen = sizeof (struct sockaddr_in);
          break;
#ifdef USE_IPV6
        case AF_INET6:
# if SIN6_LEN
	  ((struct sockaddr_in6 *) &sa)->sin6_len = hp->h_length;
# endif
	  ((struct sockaddr_in6 *) &sa)->sin6_port = htons (port);
	  memcpy (&((struct sockaddr_in6 *) &sa)->sin6_addr,
	  	  *addrs, hp->h_length);
          addrlen = sizeof (struct sockaddr_in6);
          break;
#endif
        default:
          continue;
        }

      result.ai_family = hp->h_addrtype;
      ai = dup_addrinfo (&result, &sa, addrlen);
      if (ai == NULL)
        {
	  free_ghbnctx (&ghbnctx);
          freeaddrinfo (sai);
          return EAI_MEMORY;
        }
      if (sai == NULL)
	sai = ai;
      else
	eai->ai_next = ai;
      eai = ai;
    }

  if (sai == NULL)
    {
      free_ghbnctx (&ghbnctx);
      return EAI_NODATA;
    }
  
  if (hints->ai_flags & AI_CANONNAME) 
    {
      sai->ai_canonname = malloc (strlen (hp->h_name) + 1);
      if (sai->ai_canonname == NULL)
        {
	  free_ghbnctx (&ghbnctx);
          freeaddrinfo (sai);
          return EAI_MEMORY;
        }
      strcpy (sai->ai_canonname, hp->h_name);
    }

  free_ghbnctx (&ghbnctx);
  *res = sai;
  return 0;
}

void
freeaddrinfo (struct addrinfo *ai)
{
  struct addrinfo *next;

  while (ai != NULL)
    {
      next = ai->ai_next;
      if (ai->ai_canonname != NULL)
        free (ai->ai_canonname);
      if (ai->ai_addr != NULL)
        free (ai->ai_addr);
      free (ai);
      ai = next;
    }
}

const char *
gai_strerror (int ecode)
{
  static const char *eai_descr[] =
    {
      "no error",
      "address family for nodename not supported",	/* EAI_ADDRFAMILY */
      "temporary failure in name resolution",		/* EAI_AGAIN */
      "invalid value for ai_flags",	 		/* EAI_BADFLAGS */
      "non-recoverable failure in name resolution",	/* EAI_FAIL */
      "ai_family not supported",			/* EAI_FAMILY */
      "memory allocation failure",			/* EAI_MEMORY */
      "no address associated with nodename",		/* EAI_NODATA */
      "nodename nor servname provided, or not known",	/* EAI_NONAME */
      "servname not supported for ai_socktype",		/* EAI_SERVICE */
      "ai_socktype not supported",			/* EAI_SOCKTYPE */
      "system error returned in errno",			/* EAI_SYSTEM */
      "argument buffer overflow",			/* EAI_OVERFLOW */
    };

  if (ecode < 0 || ecode > (int) (sizeof eai_descr/ sizeof eai_descr[0]))
    return "unknown error";
  return eai_descr[ecode];
}

#endif