Martin v. Löwis | 01dfdb3 | 2001-06-23 16:30:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of the project nor the names of its contributors |
| 14 | * may be used to endorse or promote products derived from this software |
| 15 | * without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef HAVE_GETADDRINFO |
| 31 | |
| 32 | /* |
| 33 | * Error return codes from getaddrinfo() |
| 34 | */ |
| 35 | #ifndef EAI_ADDRFAMILY |
| 36 | #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ |
| 37 | #define EAI_AGAIN 2 /* temporary failure in name resolution */ |
| 38 | #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ |
| 39 | #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ |
| 40 | #define EAI_FAMILY 5 /* ai_family not supported */ |
| 41 | #define EAI_MEMORY 6 /* memory allocation failure */ |
| 42 | #define EAI_NODATA 7 /* no address associated with hostname */ |
| 43 | #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ |
| 44 | #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ |
| 45 | #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ |
| 46 | #define EAI_SYSTEM 11 /* system error returned in errno */ |
| 47 | #define EAI_BADHINTS 12 |
| 48 | #define EAI_PROTOCOL 13 |
| 49 | #define EAI_MAX 14 |
| 50 | #endif |
| 51 | |
| 52 | /* |
| 53 | * Flag values for getaddrinfo() |
| 54 | */ |
| 55 | #ifndef AI_PASSIVE |
| 56 | #define AI_PASSIVE 0x00000001 /* get address to use bind() */ |
| 57 | #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ |
| 58 | #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ |
| 59 | /* valid flags for addrinfo */ |
| 60 | #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) |
| 61 | |
| 62 | #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ |
| 63 | #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ |
| 64 | #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ |
| 65 | #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ |
| 66 | /* special recommended flags for getipnodebyname */ |
| 67 | #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) |
| 68 | #endif |
| 69 | |
| 70 | /* |
| 71 | * Constants for getnameinfo() |
| 72 | */ |
| 73 | #ifndef NI_MAXHOST |
| 74 | #define NI_MAXHOST 1025 |
| 75 | #define NI_MAXSERV 32 |
| 76 | #endif |
| 77 | |
| 78 | /* |
| 79 | * Flag values for getnameinfo() |
| 80 | */ |
| 81 | #ifndef NI_NOFQDN |
| 82 | #define NI_NOFQDN 0x00000001 |
| 83 | #define NI_NUMERICHOST 0x00000002 |
| 84 | #define NI_NAMEREQD 0x00000004 |
| 85 | #define NI_NUMERICSERV 0x00000008 |
| 86 | #define NI_DGRAM 0x00000010 |
| 87 | #endif |
| 88 | |
| 89 | #ifndef HAVE_ADDRINFO |
| 90 | struct addrinfo { |
| 91 | int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ |
| 92 | int ai_family; /* PF_xxx */ |
| 93 | int ai_socktype; /* SOCK_xxx */ |
| 94 | int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ |
| 95 | size_t ai_addrlen; /* length of ai_addr */ |
| 96 | char *ai_canonname; /* canonical name for hostname */ |
| 97 | struct sockaddr *ai_addr; /* binary address */ |
| 98 | struct addrinfo *ai_next; /* next structure in linked list */ |
| 99 | }; |
| 100 | #endif |
| 101 | |
| 102 | #ifndef HAVE_SOCKADDR_STORAGE |
| 103 | /* |
| 104 | * RFC 2553: protocol-independent placeholder for socket addresses |
| 105 | */ |
| 106 | #define _SS_MAXSIZE 128 |
| 107 | #ifdef HAVE_LONG_LONG |
Martin v. Löwis | d783041 | 2001-07-19 17:37:46 +0000 | [diff] [blame] | 108 | #define _SS_ALIGNSIZE (sizeof(LONG_LONG)) |
Martin v. Löwis | 01dfdb3 | 2001-06-23 16:30:13 +0000 | [diff] [blame] | 109 | #else |
| 110 | #define _SS_ALIGNSIZE (sizeof(double)) |
| 111 | #endif |
| 112 | #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) * 2) |
| 113 | #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) * 2 - \ |
| 114 | _SS_PAD1SIZE - _SS_ALIGNSIZE) |
| 115 | |
| 116 | struct sockaddr_storage { |
| 117 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 118 | unsigned char ss_len; /* address length */ |
| 119 | unsigned char ss_family; /* address family */ |
| 120 | #else |
| 121 | unsigned short ss_family; /* address family */ |
| 122 | #endif |
| 123 | char __ss_pad1[_SS_PAD1SIZE]; |
| 124 | #ifdef HAVE_LONG_LONG |
Martin v. Löwis | d783041 | 2001-07-19 17:37:46 +0000 | [diff] [blame] | 125 | LONG_LONG __ss_align; /* force desired structure storage alignment */ |
Martin v. Löwis | 01dfdb3 | 2001-06-23 16:30:13 +0000 | [diff] [blame] | 126 | #else |
| 127 | double __ss_align; /* force desired structure storage alignment */ |
| 128 | #endif |
| 129 | char __ss_pad2[_SS_PAD2SIZE]; |
| 130 | }; |
| 131 | #endif |
| 132 | |
| 133 | #ifdef __cplusplus |
| 134 | extern "C" { |
| 135 | #endif |
| 136 | extern void freehostent Py_PROTO((struct hostent *)); |
| 137 | #ifdef __cplusplus |
| 138 | } |
| 139 | #endif |
| 140 | #endif |