1 /* $NetBSD: netdb.h,v 1.5 2022/09/23 12:15:34 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #ifndef NETDB_H 17 #define NETDB_H 1 18 19 #include <stddef.h> 20 #include <winsock2.h> 21 22 /* 23 * Define if <netdb.h> does not declare struct addrinfo. 24 */ 25 26 #if _MSC_VER < 1600 27 struct addrinfo { 28 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 29 int ai_family; /* PF_xxx */ 30 int ai_socktype; /* SOCK_xxx */ 31 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and 32 * IPv6 */ 33 size_t ai_addrlen; /* Length of ai_addr */ 34 char *ai_canonname; /* Canonical name for hostname */ 35 struct sockaddr *ai_addr; /* Binary address */ 36 struct addrinfo *ai_next; /* Next structure in linked list */ 37 }; 38 #endif /* if _MSC_VER < 1600 */ 39 40 /* 41 * Undefine all \#defines we are interested in as <netdb.h> may or may not have 42 * defined them. 43 */ 44 45 /* 46 * Error return codes from gethostbyname() and gethostbyaddr() 47 * (left in extern int h_errno). 48 */ 49 50 #undef NETDB_INTERNAL 51 #undef NETDB_SUCCESS 52 #undef HOST_NOT_FOUND 53 #undef TRY_AGAIN 54 #undef NO_RECOVERY 55 #undef NO_DATA 56 #undef NO_ADDRESS 57 58 #define NETDB_INTERNAL -1 /* see errno */ 59 #define NETDB_SUCCESS 0 /* no problem */ 60 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 61 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 62 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 63 #define NO_DATA 4 /* Valid name, no data record of requested type */ 64 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 65 66 /* 67 * Error return codes from getaddrinfo() 68 */ 69 70 #undef EAI_ADDRFAMILY 71 #undef EAI_AGAIN 72 #undef EAI_BADFLAGS 73 #undef EAI_FAIL 74 #undef EAI_FAMILY 75 #undef EAI_MEMORY 76 #undef EAI_NODATA 77 #undef EAI_NONAME 78 #undef EAI_SERVICE 79 #undef EAI_SOCKTYPE 80 #undef EAI_SYSTEM 81 #undef EAI_BADHINTS 82 #undef EAI_PROTOCOL 83 #undef EAI_MAX 84 85 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 86 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 87 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 88 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 89 #define EAI_FAMILY 5 /* ai_family not supported */ 90 #define EAI_MEMORY 6 /* memory allocation failure */ 91 #define EAI_NODATA 7 /* no address associated with hostname */ 92 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 93 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 94 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 95 #define EAI_SYSTEM 11 /* system error returned in errno */ 96 #define EAI_BADHINTS 12 97 #define EAI_PROTOCOL 13 98 #define EAI_MAX 14 99 100 /* 101 * Flag values for getaddrinfo() 102 */ 103 #undef AI_PASSIVE 104 #undef AI_CANONNAME 105 #undef AI_NUMERICHOST 106 107 #define AI_PASSIVE 0x00000001 108 #define AI_CANONNAME 0x00000002 109 #define AI_NUMERICHOST 0x00000004 110 111 /* 112 * Flag values for getipnodebyname() 113 */ 114 #undef AI_V4MAPPED 115 #undef AI_ALL 116 #undef AI_ADDRCONFIG 117 #undef AI_DEFAULT 118 119 #define AI_V4MAPPED 0x00000008 120 #define AI_ALL 0x00000010 121 #define AI_ADDRCONFIG 0x00000020 122 #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG) 123 124 /* 125 * Constants for getnameinfo() 126 */ 127 #undef NI_MAXHOST 128 #undef NI_MAXSERV 129 130 #define NI_MAXHOST 1025 131 #define NI_MAXSERV 32 132 133 /* 134 * Flag values for getnameinfo() 135 */ 136 #undef NI_NOFQDN 137 #undef NI_NUMERICHOST 138 #undef NI_NAMEREQD 139 #undef NI_NUMERICSERV 140 #undef NI_DGRAM 141 #undef NI_NUMERICSCOPE 142 143 #define NI_NOFQDN 0x00000001 144 #define NI_NUMERICHOST 0x00000002 145 #define NI_NAMEREQD 0x00000004 146 #define NI_NUMERICSERV 0x00000008 147 #define NI_DGRAM 0x00000010 148 #define NI_NUMERICSCOPE 0x00000020 /*2553bis-00*/ 149 150 /* 151 * Structures for getrrsetbyname() 152 */ 153 struct rdatainfo { 154 unsigned int rdi_length; 155 unsigned char *rdi_data; 156 }; 157 158 struct rrsetinfo { 159 unsigned int rri_flags; 160 int rri_rdclass; 161 int rri_rdtype; 162 unsigned int rri_ttl; 163 unsigned int rri_nrdatas; 164 unsigned int rri_nsigs; 165 char *rri_name; 166 struct rdatainfo *rri_rdatas; 167 struct rdatainfo *rri_sigs; 168 }; 169 170 /* 171 * Flags for getrrsetbyname() 172 */ 173 #define RRSET_VALIDATED 0x00000001 174 /* Set was dnssec validated */ 175 176 /* 177 * Return codes for getrrsetbyname() 178 */ 179 #define ERRSET_SUCCESS 0 180 #define ERRSET_NOMEMORY 1 181 #define ERRSET_FAIL 2 182 #define ERRSET_INVAL 3 183 184 #endif /* NETDB_H */ 185