1 /* netdb.h */ 2 3 #ifndef NETDB_H 4 #define NETDB_H 5 6 #include <netinet/in.h> 7 #include <errno.h> 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 14 #ifndef MAXHOSTNAMELEN 15 #define MAXHOSTNAMELEN 64 16 #endif 17 18 #define HOST_NOT_FOUND 1 19 #define TRY_AGAIN 2 20 #define NO_RECOVERY 3 21 #define NO_DATA 4 22 23 #ifndef h_errno 24 extern int *_h_errnop(void); 25 #define h_errno (*_h_errnop()) 26 #endif /* h_errno */ 27 28 struct hostent { 29 char *h_name; 30 char **h_aliases; 31 int h_addrtype; 32 int h_length; 33 char **h_addr_list; 34 }; 35 #define h_addr h_addr_list[0] 36 37 struct servent { 38 char *s_name; 39 char **s_aliases; 40 int s_port; 41 char *s_proto; 42 }; 43 44 /* 45 * Assumption here is that a network number 46 * fits in an in_addr_t -- probably a poor one. 47 */ 48 struct netent { 49 char *n_name; /* official name of net */ 50 char **n_aliases; /* alias list */ 51 int n_addrtype; /* net address type */ 52 in_addr_t n_net; /* network # */ 53 }; 54 55 struct protoent { 56 char *p_name; /* official protocol name */ 57 char **p_aliases; /* alias list */ 58 int p_proto; /* protocol # */ 59 }; 60 61 struct addrinfo { 62 int ai_flags; /* input flags */ 63 int ai_family; /* protocol family for socket */ 64 int ai_socktype; /* socket type */ 65 int ai_protocol; /* protocol for socket */ 66 socklen_t ai_addrlen; /* length of socket-address */ 67 struct sockaddr *ai_addr; /* socket-address for socket */ 68 char *ai_canonname; /* canonical name for service location (iff req) */ 69 struct addrinfo *ai_next; /* pointer to next in list */ 70 }; 71 72 73 struct hostent *gethostbyname(const char *hostname); 74 struct hostent *gethostbyaddr(const char *hostname, int len, int type); 75 struct servent *getservbyname(const char *name, const char *proto); 76 void herror(const char *); 77 unsigned long inet_addr(const char *a_addr); 78 char *inet_ntoa(struct in_addr addr); 79 80 int gethostname(char *hostname, size_t hostlen); 81 82 /* BE specific, because of lack of UNIX passwd functions */ 83 int getusername(char *username, size_t userlen); 84 int getpassword(char *password, size_t passlen); 85 86 87 /* These are new! */ 88 struct netent *getnetbyaddr (in_addr_t, int); 89 struct netent *getnetbyname (const char *); 90 struct netent *getnetent (void); 91 struct protoent *getprotoent (void); 92 struct protoent *getprotobyname (const char *); 93 struct protoent *getprotobynumber (int); 94 struct hostent *gethostbyname2 (const char *, int); 95 struct servent *getservbyport (int, const char *); 96 97 int getaddrinfo (const char *, const char *, 98 const struct addrinfo *, 99 struct addrinfo **); 100 void freeaddrinfo (struct addrinfo *); 101 int getnameinfo (const struct sockaddr *, socklen_t, 102 char *, size_t, char *, size_t, 103 int); 104 105 void sethostent (int); 106 void setnetent (int); 107 void setprotoent (int); 108 void setservent (int); 109 110 void endhostent (void); 111 void endnetent (void); 112 void endprotoent (void); 113 void endservent (void); 114 115 #define _PATH_HEQUIV "/etc/hosts.equiv" 116 #define _PATH_HOSTS "/etc/hosts" 117 #define _PATH_NETWORKS "/etc/networks" 118 #define _PATH_PROTOCOLS "/etc/protocols" 119 #define _PATH_SERVICES "/etc/services" 120 121 /* 122 * Error return codes from gethostbyname() and gethostbyaddr() 123 * (left in extern int h_errno). 124 */ 125 126 #define NETDB_INTERNAL -1 /* see errno */ 127 #define NETDB_SUCCESS 0 /* no problem */ 128 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 129 #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ 130 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 131 #define NO_DATA 4 /* Valid name, no data record of requested type */ 132 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 133 134 /* Values for getaddrinfo() and getnameinfo() */ 135 #define AI_PASSIVE 1 /* socket address is intended for bind() */ 136 #define AI_CANONNAME 2 /* request for canonical name */ 137 #define AI_NUMERICHOST 4 /* don't ever try nameservice */ 138 #define AI_EXT 8 /* enable non-portable extensions */ 139 /* valid flags for addrinfo */ 140 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 141 142 #define NI_NUMERICHOST 1 /* return the host address, not the name */ 143 #define NI_NUMERICSERV 2 /* return the service address, not the name */ 144 #define NI_NOFQDN 4 /* return a short name if in the local domain */ 145 #define NI_NAMEREQD 8 /* fail if either host or service name is unknown */ 146 #define NI_DGRAM 16 /* look up datagram service instead of stream */ 147 #define NI_WITHSCOPEID 32 /* KAME hack: attach scopeid to host portion */ 148 149 #define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */ 150 #define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */ 151 152 /* 153 * Scope delimit character (KAME hack) 154 */ 155 #define SCOPE_DELIMITER '%' 156 157 #define EAI_BADFLAGS -1 /* invalid value for ai_flags */ 158 #define EAI_NONAME -2 /* name or service is not known */ 159 #define EAI_AGAIN -3 /* temporary failure in name resolution */ 160 #define EAI_FAIL -4 /* non-recoverable failure in name resolution */ 161 #define EAI_NODATA -5 /* no address associated with name */ 162 #define EAI_FAMILY -6 /* ai_family not supported */ 163 #define EAI_SOCKTYPE -7 /* ai_socktype not supported */ 164 #define EAI_SERVICE -8 /* service not supported for ai_socktype */ 165 #define EAI_ADDRFAMILY -9 /* address family for name not supported */ 166 #define EAI_MEMORY -10 /* memory allocation failure */ 167 #define EAI_SYSTEM -11 /* system error (code indicated in errno) */ 168 #define EAI_BADHINTS -12 /* invalid value for hints */ 169 #define EAI_PROTOCOL -13 /* resolved protocol is unknown */ 170 171 172 /* 173 * Flags for getrrsetbyname() 174 */ 175 #define RRSET_VALIDATED 1 176 177 /* 178 * Return codes for getrrsetbyname() 179 */ 180 #define ERRSET_SUCCESS 0 181 182 #ifdef __cplusplus 183 } 184 #endif 185 186 #endif /* NETDB_H */ 187