12
  	   #ˆÄÊ0ÀÇ  +   %ˆl–Ðz¾”êe¶¥6 ]¸&n *bÑ¿Ë„o¾ÿ_†I|¥�+ÂÉ >    %/*
 * ProFTPD - FTP server daemon
 * Copyright (c) 2003-2021 The ProFTPD Project team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
 *
 * As a special exemption, The ProFTPD Project team and other respective
 * copyright holders give permission to link this program with OpenSSL, and
 * distribute the resulting executable, without including the source code for
 * OpenSSL in the source distribution.
 */

/* Network address API */

#ifndef PR_NETADDR_H
#define PR_NETADDR_H

#include "os.h"
#include "pool.h"

#ifndef INET_ADDRSTRLEN
# define INET_ADDRSTRLEN        16
#endif /* INET_ADDRSTRLEN */

#ifndef INET6_ADDRSTRLEN
# define INET6_ADDRSTRLEN       46
#endif /* INET6_ADDRSTRLEN */

struct netaddr_struc {
  int na_family;

  /* Note: this assumes that DNS names have a maximum size of
   * 256 characters.
   */
  char na_dnsstr[256];
  int na_have_dnsstr;

#ifdef PR_USE_IPV6
  char na_ipstr[INET6_ADDRSTRLEN];
#else
  char na_ipstr[INET_ADDRSTRLEN];
#endif /* PR_USE_IPV6 */
  int na_have_ipstr;

  /* Note: at some point, this union might/should be replaced with
   * struct sockaddr_storage.  Why?  The sockaddr_storage struct is
   * better defined to be aligned on OS/arch boundaries, for more efficient
   * allocation/access.
   */

  union {
    struct sockaddr_in v4;
#ifdef PR_USE_IPV6
    struct sockaddr_in6 v6;
#endif /* PR_USE_IPV6 */
  } na_addr;
};

typedef struct netaddr_struc pr_netaddr_t;

#ifndef HAVE_STRUCT_ADDRINFO
struct addrinfo {

  /* AI_PASSIVE, AI_CANONNAME */
  int ai_flags;

  /* AF/PF_xxx */
  int ai_family;

  /* SOCK_xxx */
  int ai_socktype;

  /* IPPROTO_xxx for IPv4/v6 */
  int ai_protocol;

  /* Length of ai_addr */
  int ai_addrlen;

  /* Canonical name for host */
  char *ai_canonname;

  /* Binary address */
  struct sockaddr *ai_addr;

  /* Next structure in the linked list */
  struct addrinfo *ai_next;
};
#endif /* HAVE_STRUCT_ADDRINFO */

#if defined(HAVE_GETADDRINFO) && !defined(PR_USE_GETADDRINFO)
/* Use the system getaddrinfo(2) and freeaddrinfo(2) by redefining the
 * 'pr_getaddrinfo' and 'pr_freeaddrinfo' symbols to be 'getaddrinfo' and
 * 'freeaddrinfo', respectively.
 */
# define pr_getaddrinfo         getaddrinfo
# define pr_freeaddrinfo        freeaddrinfo
#else
int pr_getaddrinfo(const char *, const char *, const struct addrinfo *,
  struct addrinfo **);
void pr_freeaddrinfo(struct addrinfo *);
#endif /* HAVE_GETNAMEINFO and !PR_USE_GETNAMEINFO */

/* These AI_ defines are for use by getaddrinfo(3). */

/* Indicates that the socket is intended for bind()+listen(). */
#ifndef AI_PASSIVE
# define AI_PASSIVE     1
#endif /* AI_PASSIVE */

/* Return the canonical name. */
#ifndef AI_CANONNAME
# define AI_CANONNAME   2
#endif /* AI_CANONNAME */

/* The following EAI_ defines are for errors. */

/* Host address family not supported. */
#ifndef EAI_ADDRFAMILY
# define EAI_ADDRFAMILY -1
#endif /* EAI_ADDRFAMILY */

/* Temporary failure in name resolution. */
#ifndef EAI_AGAIN
# define EAI_AGAIN      -2
#endif /* EAI_AGAIN */

/* Invalid value for ai_flags. */
#ifndef EAI_BADFLAGS
# define EAI_BADFLAGS   -3
#endif /* EAI_BADFLAGS */

/* Non-recoverable failure in name resolution. */
#ifndef EAI_FAIL
# define EAI_FAIL       -4
#endif /* EAI_FAIL */

/* ai_family not supported. */
#ifndef EAI_FAMILY
# define EAI_FAMILY     -5
#endif /* EAI_FAMILY */
