1explain_getaddrinfo(3)     Library Functions Manual     explain_getaddrinfo(3)
2
3
4

NAME

6       explain_getaddrinfo - explain getaddrinfo(3) errors
7

SYNOPSIS

9       #include <libexplain/getaddrinfo.h>
10       const  char  *explain_errcode_getaddrinfo(int errnum, const char *node,
11       const char *service, const  struct  addrinfo  *hints,  struct  addrinfo
12       **res);
13       void   explain_message_errcode_getaddrinfo(char   *message,   int  mes‐
14       sage_size, int errnum, const char *node,  const  char  *service,  const
15       struct addrinfo *hints, struct addrinfo **res);
16

DESCRIPTION

18       These  functions may be used to obtain explanations for errors returned
19       by the getaddrinfo(3) system call.
20
21   explain_errcode_getaddrinfo
22       const char *explain_errcode_getaddrinfo(int errnum, const  char  *node,
23       const  char  *service,  const  struct  addrinfo *hints, struct addrinfo
24       **res);
25
26       The explain_errcode_getaddrinfo function is used to obtain an  explana‐
27       tion of an error returned by the getaddrinfo(3) system call.  The least
28       the message will contain is the  value  of  gai_strerror(errcode),  but
29       usually  it  will  do much better, and indicate the underlying cause in
30       more detail.
31
32       This function is intended to be used in a fashion similar to  the  fol‐
33       lowing example:
34              int errcode = getaddrinfo(node, service, hints, res);
35              if (errncode == GAI_SYSTEM)
36                  errcode = errno;
37              if (errcode)
38              {
39                  fprintf(stderr, "%s\n", explain_errcode_getaddrinfo(errcode,
40                      node, service, hints, res));
41                  exit(EXIT_FAILURE);
42              }
43
44       The   above   code   example   is   available   as  the  explain_getad‐
45       drinfo_or_die(3) function.
46
47       errnum  The error value to be decoded, usually obtained from the  errno
48               global  variable  just before this function is called.  This is
49               necessary if you need to call any code between the system  call
50               to  be explained and this function, because many libc functions
51               will alter the value of errno.
52
53       node    The original node, exactly as passed to the getaddrinfo(3) sys‐
54               tem call.
55
56       service The  original  service, exactly as passed to the getaddrinfo(3)
57               system call.
58
59       hints   The original hints, exactly as  passed  to  the  getaddrinfo(3)
60               system call.
61
62       res     The  original res, exactly as passed to the getaddrinfo(3) sys‐
63               tem call.
64
65       Returns:
66               The message explaining  the  error.   This  message  buffer  is
67               shared by all libexplain functions which do not supply a buffer
68               in their argument list.  This will be overwritten by  the  next
69               call  to  any  libexplain  function  which  shares this buffer,
70               including other threads.
71
72       Note: This function is not thread safe, because it shares a return buf‐
73       fer across all threads, and many other functions in this library.
74
75   explain_message_errno_getaddrinfo
76       void explain_message_errno_getaddrinfo(char *message, int message_size,
77       int errnum,  const  char  *node,  const  char  *service,  const  struct
78       addrinfo *hints, struct addrinfo **res);
79
80       The explain_message_errno_getaddrinfo function may be used to obtain an
81       explanation of an error returned by  the  getaddrinfo(3)  system  call.
82       The  least  the  message will contain is the value of strerror(errnum),
83       but usually it will do much better, and indicate the  underlying  cause
84       in more detail.
85
86       This  function  is intended to be used in a fashion similar to the fol‐
87       lowing example:
88              int errcode = getaddrinfo(node, service, hints, res);
89              if (errnode == EAI_SYSTEM)
90                  errcode = errno;
91              if (errcode)
92              {
93                  char message[3000];
94                  explain_message_errcode_getaddrinfo(message, sizeof(message),
95                      errcode, node, service, hints, res);
96                  fprintf(stderr, "%s\n", message);
97                  exit(EXIT_FAILURE);
98              }
99
100       The above code example is available pre‐packaged as the  explain_getad‐
101       drinfo_or_die(3) function.
102
103       message The  location  in  which  to  store the returned message.  If a
104               suitable message return buffer is supplied,  this  function  is
105               thread safe.
106
107       message_size
108               The  size  in  bytes  of  the  location  in  which to store the
109               returned message.
110
111       errnum  The error value to be decoded, usually obtained from the  errno
112               global  variable  just before this function is called.  This is
113               necessary if you need to call any code between the system  call
114               to  be explained and this function, because many libc functions
115               will alter the value of errno.
116
117       node    The original node, exactly as passed to the getaddrinfo(3) sys‐
118               tem call.
119
120       service The  original  service, exactly as passed to the getaddrinfo(3)
121               system call.
122
123       hints   The original hints, exactly as  passed  to  the  getaddrinfo(3)
124               system call.
125
126       res     The  original res, exactly as passed to the getaddrinfo(3) sys‐
127               tem call.
128

SEE ALSO

130       getaddrinfo(3)
131               network address and
132
133       explain_getaddrinfo_or_die(3)
134               network address and and report errors
135
137       libexplain version 1.4
138       Copyright (C) 2008 Peter Miller
139
140
141
142                                                        explain_getaddrinfo(3)
Impressum