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