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

NAME

6       explain_getpeername - explain getpeername(2) errors
7

SYNOPSIS

9       #include <libexplain/getpeername.h>
10       const char *explain_getpeername(int fildes, struct sockaddr *sock_addr,
11       socklen_t *sock_addr_size);
12       const char *explain_errno_getpeername(int errnum,  int  fildes,  struct
13       sockaddr *sock_addr, socklen_t *sock_addr_size);
14       void  explain_message_getpeername(char  *message, int message_size, int
15       fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size);
16       void explain_message_errno_getpeername(char *message, int message_size,
17       int   errnum,   int   fildes,  struct  sockaddr  *sock_addr,  socklen_t
18       *sock_addr_size);
19

DESCRIPTION

21       These functions may be used to obtain explanations for errors  returned
22       by the getpeername(2) system call.
23
24   explain_getpeername
25       const char *explain_getpeername(int fildes, struct sockaddr *sock_addr,
26       socklen_t *sock_addr_size);
27
28       The explain_getpeername function is used to obtain an explanation of an
29       error  returned  by the getpeername(2) system call.  The least the mes‐
30       sage will contain is the value of strerror(errno), but usually it  will
31       do much better, and indicate the underlying cause in more detail.
32
33       The  errno global variable will be used to obtain the error value to be
34       decoded.
35
36       This function is intended to be used in a fashion similar to  the  fol‐
37       lowing example:
38              struct sockaddr sock_addr;
39              socklen_t sock_addr_len = sizeof(sock_addr);
40              if (getpeername(fildes, &sock_addr, &sock_addr_size) < 0)
41              {
42                  fprintf(stderr, "%s\n", explain_getpeername(fildes,
43                      &sock_addr, &sock_addr_size));
44                  exit(EXIT_FAILURE);
45              }
46
47       The  above  code  example is available pre‐packaged as the explain_get‐
48       peername_or_die(3) function.
49
50       fildes  The original fildes, exactly as passed  to  the  getpeername(2)
51               system call.
52
53       sock_addr
54               The original sock_addr, exactly as passed to the getpeername(2)
55               system call.
56
57       sock_addr_size
58               The original sock_addr_size, exactly as passed to the  getpeer‐
59               name(2) system call.
60
61       Returns:
62               The  message  explaining  the  error.   This  message buffer is
63               shared by all libexplain functions which do not supply a buffer
64               in  their  argument list.  This will be overwritten by the next
65               call to any  libexplain  function  which  shares  this  buffer,
66               including other threads.
67
68       Note: This function is not thread safe, because it shares a return buf‐
69       fer across all threads, and many other functions in this library.
70
71   explain_errno_getpeername
72       const char *explain_errno_getpeername(int errnum,  int  fildes,  struct
73       sockaddr *sock_addr, socklen_t *sock_addr_size);
74
75       The explain_errno_getpeername function is used to obtain an explanation
76       of an error returned by the getpeername(2) system call.  The least  the
77       message  will  contain is the value of strerror(errnum), but usually it
78       will do much better, and indicate the underlying cause in more detail.
79
80       This function is intended to be used in a fashion similar to  the  fol‐
81       lowing example:
82              struct sockaddr sock_addr;
83              socklen_t sock_addr_len = sizeof(sock_addr);
84              if (getpeername(fildes, &sock_addr, &sock_addr_size) < 0)
85              {
86                  int err = errno;
87                  fprintf(stderr, "%s\n", explain_errno_getpeername(err,
88                      fildes, &sock_addr, &sock_addr_size));
89                  exit(EXIT_FAILURE);
90              }
91
92       The  above  code  example is available pre‐packaged as the explain_get‐
93       peername_or_die(3) function.
94
95       errnum  The error value to be decoded, usually obtained from the  errno
96               global  variable  just before this function is called.  This is
97               necessary if you need to call any code between the system  call
98               to  be explained and this function, because many libc functions
99               will alter the value of errno.
100
101       fildes  The original fildes, exactly as passed  to  the  getpeername(2)
102               system call.
103
104       sock_addr
105               The original sock_addr, exactly as passed to the getpeername(2)
106               system call.
107
108       sock_addr_size
109               The original sock_addr_size, exactly as passed to the  getpeer‐
110               name(2) system call.
111
112       Returns:
113               The  message  explaining  the  error.   This  message buffer is
114               shared by all libexplain functions which do not supply a buffer
115               in  their  argument list.  This will be overwritten by the next
116               call to any  libexplain  function  which  shares  this  buffer,
117               including other threads.
118
119       Note: This function is not thread safe, because it shares a return buf‐
120       fer across all threads, and many other functions in this library.
121
122   explain_message_getpeername
123       void explain_message_getpeername(char *message, int  message_size,  int
124       fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size);
125
126       The  explain_message_getpeername  function  may  be  used to  obtain an
127       explanation of an error returned by  the  getpeername(2)  system  call.
128       The least the message will contain is the value of strerror(errno), but
129       usually it will do much better, and indicate the  underlying  cause  in
130       more detail.
131
132       The  errno global variable will be used to obtain the error value to be
133       decoded.
134
135       This function is intended to be used in a fashion similar to  the  fol‐
136       lowing example:
137              struct sockaddr sock_addr;
138              socklen_t sock_addr_len = sizeof(sock_addr);
139              if (getpeername(fildes, &sock_addr, &sock_addr_size) < 0)
140              {
141                  char message[3000];
142                  explain_message_getpeername(message, sizeof(message),
143                      fildes, &sock_addr, &sock_addr_size);
144                  fprintf(stderr, "%s\n", message);
145                  exit(EXIT_FAILURE);
146              }
147
148       The  above  code  example is available pre‐packaged as the explain_get‐
149       peername_or_die(3) function.
150
151       message The location in which to store  the  returned  message.   If  a
152               suitable  message  return  buffer is supplied, this function is
153               thread safe.
154
155       message_size
156               The size in bytes  of  the  location  in  which  to  store  the
157               returned message.
158
159       fildes  The  original  fildes,  exactly as passed to the getpeername(2)
160               system call.
161
162       sock_addr
163               The original sock_addr, exactly as passed to the getpeername(2)
164               system call.
165
166       sock_addr_size
167               The  original sock_addr_size, exactly as passed to the getpeer‐
168               name(2) system call.
169
170   explain_message_errno_getpeername
171       void explain_message_errno_getpeername(char *message, int message_size,
172       int   errnum,   int   fildes,  struct  sockaddr  *sock_addr,  socklen_t
173       *sock_addr_size);
174
175       The explain_message_errno_getpeername function may be used to obtain an
176       explanation  of  an  error  returned by the getpeername(2) system call.
177       The least the message will contain is the  value  of  strerror(errnum),
178       but  usually  it will do much better, and indicate the underlying cause
179       in more detail.
180
181       This function is intended to be used in a fashion similar to  the  fol‐
182       lowing example:
183              struct sockaddr sock_addr;
184              socklen_t sock_addr_len = sizeof(sock_addr);
185              if (getpeername(fildes, &sock_addr, &sock_addr_size) < 0)
186              {
187                  int err = errno;
188                  char message[3000];
189                  explain_message_errno_getpeername(message, sizeof(message),
190                      err, fildes, &sock_addr, &sock_addr_size);
191                  fprintf(stderr, "%s\n", message);
192                  exit(EXIT_FAILURE);
193              }
194
195       The  above  code  example is available pre‐packaged as the explain_get‐
196       peername_or_die(3) function.
197
198       message The location in which to store  the  returned  message.   If  a
199               suitable  message  return  buffer is supplied, this function is
200               thread safe.
201
202       message_size
203               The size in bytes  of  the  location  in  which  to  store  the
204               returned message.
205
206       errnum  The  error value to be decoded, usually obtained from the errno
207               global variable just before this function is called.   This  is
208               necessary  if you need to call any code between the system call
209               to be explained and this function, because many libc  functions
210               will alter the value of errno.
211
212       fildes  The  original  fildes,  exactly as passed to the getpeername(2)
213               system call.
214
215       sock_addr
216               The original sock_addr, exactly as passed to the getpeername(2)
217               system call.
218
219       sock_addr_size
220               The  original sock_addr_size, exactly as passed to the getpeer‐
221               name(2) system call.
222

SEE ALSO

224       getpeername(2)
225               get name of connected peer socket
226
227       explain_getpeername_or_die(3)
228               get name of connected peer socket and report errors
229
231       libexplain version 0.40
232       Copyright (C) 2009 Peter Miller
233
234
235
236                                                        explain_getpeername(3)
Impressum