text: /*	$Id: compat.h 23435 2013-02-07 10:46:13Z m-oki $	*/
  
  /*
   * Copyright (c) 2012, Internet Initiative Japan, Inc.
   * 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.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
   */
  
  /*	$NetBSD: netdb.h,v 1.48.2.2 2005/04/21 16:59:28 tron Exp $	*/
  
  /*
   * Copyright (c) 1980, 1983, 1988, 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. 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) 1995, 1996, 1997, and 1998 WIDE Project.
   * 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 WIDE Project and
   *    its contributors.
   * 4. Neither the name of the project 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 PROJECT 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 PROJECT 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.
   * -
   * --Copyright--
   */
  
  /*
   *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
   *	Id: netdb.h,v 1.12.2.1.4.4 2004/03/16 02:19:19 marka Exp
   */
  
  #ifndef __COMPAT_H__
  #define __COMPAT_H__
  
  #include <sys/types.h>
  
  #ifndef HAVE_STRLCPY
  #define strlcpy arms_private_strlcpy
  size_t strlcpy(char *, const char *, size_t);
  #endif /* HAVE_STRLCPY */
  
  #ifndef HAVE_STRTOK_R
  char *strtok_r(char *,const char *, char **);
  #endif
  
  #ifndef HAVE_GETADDRINFO
  struct addrinfo {
  	int	ai_flags;	/* AI_xxx */
  	int	ai_family;	/* PF_xxx */
  	int	ai_socktype;	/* SOCK_xxx */
  	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  	socklen_t ai_addrlen;	/* length of ai_addr */
  	char	*ai_canonname;	/* canonical name for hostname */
  	struct sockaddr *ai_addr;	/* binary address */
  	struct addrinfo *ai_next;	/* next structure in linked list */
  };
  
  /*
   * Flag values for getaddrinfo()
   */
  #define	AI_PASSIVE	0x00000001 /* get address to use bind() */
  #define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
  #define	AI_NUMERICHOST	0x00000004 /* prevent host name resolution */
  #define	AI_NUMERICSERV	0x00000008 /* prevent service name resolution */
  
  /*
   * Error return codes from getaddrinfo()
   */
  #define	EAI_ADDRFAMILY	 1	/*%< address family for hostname not supported */
  #define	EAI_AGAIN	 2	/*%< temporary failure in name resolution */
  #define	EAI_BADFLAGS	 3	/*%< invalid value for ai_flags */
  #define	EAI_FAIL	 4	/*%< non-recoverable failure in name resolution */
  #define	EAI_FAMILY	 5	/*%< ai_family not supported */
  #define	EAI_MEMORY	 6	/*%< memory allocation failure */
  #define	EAI_NODATA	 7	/*%< no address associated with hostname */
  #define	EAI_NONAME	 8	/*%< hostname nor servname provided, or not known */
  #define	EAI_SERVICE	 9	/*%< servname not supported for ai_socktype */
  #define	EAI_SOCKTYPE	10	/*%< ai_socktype not supported */
  #define	EAI_SYSTEM	11	/*%< system error returned in errno */
  #define	EAI_BADHINTS	12	/* invalid value for hints */
  #define	EAI_PROTOCOL	13	/* resolved protocol is unknown */
  #define	EAI_OVERFLOW	14	/* argument buffer overflow */
  
  int getaddrinfo(const char *, const char *, const struct addrinfo *,
  		struct addrinfo **);
  void freeaddrinfo(struct addrinfo *);
  
  #endif /* HAVE_GETADDRINFO */
  
  #ifndef HAVE_GETNAMEINFO
  /*
   * Flag values for getnameinfo()
   */
  #define	NI_NUMERICHOST	0x00000002
  #define	NI_NUMERICSERV	0x00000008
  
  int getnameinfo(const struct sockaddr *, socklen_t, char *,
  		size_t, char *, size_t, int);
  #endif /* HAVE_GETNAMEINFO */
  
  #ifndef HAVE_HTONS
  /* Interix also has no htons(). */
  static inline uint16_t
  htons(uint16_t a)
  {
  	uint8_t tmp[2];
  	tmp[0] = ((char *)&a)[1];
  	tmp[1] = ((char *)&a)[0];
  	return *(uint16_t *)tmp;
  }
  
  #define ntohs htons
  #endif
  
  #endif /* __COMPAT_H__ */
  