KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
netdb.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 netdb.h
4 Copyright (C) 2014 Lawrence Sebald
5
6*/
7
8/** \file netdb.h
9 \brief Network address database functionality.
10 \ingroup network_db
11
12 This file contains functions related to network address lookups, usually
13 performed through DNS.
14
15 \author Lawrence Sebald
16*/
17
18#ifndef __NETDB_H
19#define __NETDB_H
20
21#include <sys/cdefs.h>
22
23__BEGIN_DECLS
24
25#include <netinet/in.h>
26#include <sys/socket.h>
27#include <inttypes.h>
28
29/** \defgroup network_db Address Database
30 \brief Network Address Database Functionality
31 \ingroup networking
32*/
33
34/** \brief Network host entry.
35 \ingroup network_db
36
37 This structure describes a network host entry in the address database. When
38 looking up an address with the gethostbyname() function, one of these will
39 be returned with information about the host.
40
41 \headerfile netdb.h
42*/
43struct hostent {
44 char *h_name; /**< \brief Official name of the host. */
45 char **h_aliases; /**< \brief Alternative host names. */
46 int h_addrtype; /**< \brief Address type. */
47 int h_length; /**< \brief Length of address, in bytes. */
48 char **h_addr_list; /**< \brief Network addresses of host. */
49#define h_addr h_addr_list[0] /**< \brief Primary network address. */
50};
51
52/** \brief Network address information structure.
53 \ingroup network_db
54
55 This structure describes information on an address in the database. This
56 structure is used by functions such as getaddrinfo() to return information
57 about the specified host.
58
59 \headerfile netdb.h
60*/
61struct addrinfo {
62 int ai_flags; /**< \brief Input flags.
63 \see addrinfo_flags */
64 int ai_family; /**< \brief Socket address family. */
65 int ai_socktype; /**< \brief Socket type. */
66 int ai_protocol; /**< \brief Socket protocol. */
67 socklen_t ai_addrlen; /**< \brief Address length. */
68 struct sockaddr *ai_addr; /**< \brief Address structure. */
69 char *ai_canonname; /**< \brief Canonical name. */
70 struct addrinfo *ai_next; /**< \brief Next address entry (if any). */
71};
72
73/** \brief Error value for gethostbyname().
74 \ingroup network_db
75 \see herrno_vals */
76extern int h_errno;
77
78/** \defgroup herrno_vals h_errno Error Values
79 \brief Error values for the h_errno variable
80 \ingroup network_db
81
82 These are the possible values for h_errno, indicating errors returns from
83 the gethostbyname() function.
84
85 @{
86*/
87#define HOST_NOT_FOUND 1 /**< \brief Hostname not found. */
88#define TRY_AGAIN 2 /**< \brief Try the request again. */
89#define NO_RECOVERY 3 /**< \brief A non-recoverable error. */
90#define NO_DATA 4 /**< \brief Host found, but no data. */
91/** @} */
92
93/** \defgroup addrinfo_errors getaddrinfo() Error Values
94 \brief Errors for the getaddrinfo() function
95 \ingroup network_db
96
97 These are the possible error return values from the getaddrinfo() function.
98
99 @{
100*/
101#define EAI_AGAIN 1 /**< \brief Try the request again. */
102#define EAI_BADFLAGS 2 /**< \brief Invalid hint flags. */
103#define EAI_FAIL 3 /**< \brief A non-recoverable error. */
104#define EAI_FAMILY 4 /**< \brief Invalid address family. */
105#define EAI_MEMORY 5 /**< \brief Memory allocation error. */
106#define EAI_NONAME 6 /**< \brief Hostname not found. */
107#define EAI_SERVICE 7 /**< \brief Invalid service value. */
108#define EAI_SOCKTYPE 8 /**< \brief Invalid socket type. */
109#define EAI_SYSTEM 9 /**< \brief System error, check errno. */
110#define EAI_OVERFLOW 10 /**< \brief Argument buffer overflow. */
111/** @} */
112
113/** \defgroup addrinfo_flags addrinfo ai_flags
114 \brief Flags for ai_flags in struct addrinfo
115 \ingroup network_db
116
117 These are the flags that can be set in the ai_flags field of struct
118 addrinfo. These values can be bitwise ORed together.
119
120 Currently only AI_PASSIVE is actually supported by the getaddrinfo()
121 function.
122
123 @{
124*/
125#define AI_PASSIVE 0x00000001 /**< \brief Address intended for bind(). */
126#define AI_CANONNAME 0x00000002 /**< \brief Request canonical name. */
127#define AI_NUMERICHOST 0x00000004 /**< \brief Inhibit host resolution. */
128#define AI_NUMERICSERV 0x00000008 /**< \brief Inhibit service resolution. */
129#define AI_V4MAPPED 0x00000010 /**< \brief Return v4-mapped IPv6 addrs. */
130#define AI_ALL 0x00000020 /**< \brief Query for both IPv4 and IPv6. */
131#define AI_ADDRCONFIG 0x00000040 /**< \brief Only query for IPv4/IPv6 addrs
132 the system has a valid addr. */
133/** @} */
134
135/** \brief Free an address information structure returned by getaddrinfo().
136 \ingroup network_db
137
138 This function cleans up any memory associated with the specified
139 struct addrinfo, which was returned previously by a call to getaddrinfo().
140
141 \param ai The struct addrinfo to clean up.
142*/
143void freeaddrinfo(struct addrinfo *ai);
144
145/** \brief Get information about a specified address.
146 \ingroup network_db
147
148 This function translates the name of a host and service into a set of socket
149 addresses and related information to be used in creating a socket. This
150 includes potentially looking up the host information in the network address
151 database (and thus in DNS possibly as well).
152
153 \param nodename The host to look up.
154 \param servname The service to look up.
155 \param hints Hints used in aiding lookup.
156 \param res The resulting address information.
157 \return 0 on success, non-zero error code on failure.
158 \see addrinfo_errors
159*/
160int getaddrinfo(const char *nodename, const char *servname,
161 const struct addrinfo *hints, struct addrinfo **res);
162
163/** \brief Look up a host by its name.
164 \ingroup network_db
165
166 This function queries the network address database (possibly recursively)
167 for the network address of the specified hostname. This will first search
168 any local databases before querying remote databases (such as a DNS server)
169 for the host specified.
170
171 \param name The hostname to look up.
172 \return A pointer to a host entry on success or NULL on
173 failure. h_errno is set on failure to indicate the
174 error that occurred.
175
176 \note This function is non-reentrant. getaddrinfo() should
177 (in general) be used instead of this function.
178*/
179struct hostent *gethostbyname(const char *name);
180
181/** \brief Look up a host by its name and address family.
182 \ingroup network_db
183
184 This function queries the network address database (possibly recursively)
185 for the network address of the specified hostname. This will first search
186 any local databases before querying remote databases (such as a DNS server)
187 for the host specified.
188
189 This function allows you to specify the address family that you wish the
190 returned hostent to contain. This function is a GNU extension and has not
191 been specified by any POSIX specification.
192
193 \param name The hostname to look up.
194 \param af The address family to use for lookups (AF_INET or
195 AF_INET6).
196 \return A pointer to a host entry on success or NULL on
197 failure. h_errno is set on failure to indicate the
198 error that occurred.
199
200 \note This function is non-reentrant. getaddrinfo() should
201 (in general) be used instead of this function.
202*/
203struct hostent *gethostbyname2(const char *name, int af);
204
205__END_DECLS
206
207#endif /* !__NETDB_H */
int h_errno
Error value for gethostbyname().
void freeaddrinfo(struct addrinfo *ai)
Free an address information structure returned by getaddrinfo().
struct hostent * gethostbyname2(const char *name, int af)
Look up a host by its name and address family.
int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
Get information about a specified address.
struct hostent * gethostbyname(const char *name)
Look up a host by its name.
__uint32_t socklen_t
Socket length type.
Definition socket.h:39
Definitions for the Internet address family.
Main sockets header.
Network address information structure.
Definition netdb.h:61
struct sockaddr * ai_addr
Address structure.
Definition netdb.h:68
char * ai_canonname
Canonical name.
Definition netdb.h:69
int ai_socktype
Socket type.
Definition netdb.h:65
int ai_protocol
Socket protocol.
Definition netdb.h:66
socklen_t ai_addrlen
Address length.
Definition netdb.h:67
struct addrinfo * ai_next
Next address entry (if any).
Definition netdb.h:70
int ai_flags
Input flags.
Definition netdb.h:62
int ai_family
Socket address family.
Definition netdb.h:64
Network host entry.
Definition netdb.h:43
int h_addrtype
Address type.
Definition netdb.h:46
char * h_name
Official name of the host.
Definition netdb.h:44
char ** h_addr_list
Network addresses of host.
Definition netdb.h:48
int h_length
Length of address, in bytes.
Definition netdb.h:47
char ** h_aliases
Alternative host names.
Definition netdb.h:45
Socket address structure.
Definition socket.h:47