libexplain  1.4.D001
Functions
libexplain/getaddrinfo.h File Reference

explain getaddrinfo(3) errors More...

#include <libexplain/gcc_attributes.h>

Go to the source code of this file.

Functions

void explain_getaddrinfo_or_die (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
int explain_getaddrinfo_on_error (const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
const char * explain_errcode_getaddrinfo (int errnum, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) LIBEXPLAIN_WARN_UNUSED_RESULT
void explain_message_errcode_getaddrinfo (char *message, int message_size, int errcode, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)

Detailed Description

explain getaddrinfo(3) errors

Definition in file getaddrinfo.h.


Function Documentation

const char* explain_errcode_getaddrinfo ( int  errnum,
const char *  node,
const char *  service,
const struct addrinfo *  hints,
struct addrinfo **  res 
)

The explain_errcode_getaddrinfo function is used to obtain an explanation of an error returned by the getaddrinfo(3) system call. The least the message will contain is the value of gai_strerror(errcode), but usually it will do much better, and indicate the underlying cause in more detail.

This function is intended to be used in a fashion similar to the following example:

 int errcode = getaddrinfo(node, service, hints, res);
 if (errcode == EAI_SYSTEM)
     errcode = errno;
 if (errcode)
 {
     fprintf(stderr, "%s\n", explain_errcode_getaddrinfo(errcode,
         node, service, hints, res));
     exit(EXIT_FAILURE);
 }
Parameters:
errnumThe error value to be decoded, as returned by the getaddrinfo(3) system call.
nodeThe original node, exactly as passed to the getaddrinfo(3) system call.
serviceThe original service, exactly as passed to the getaddrinfo(3) system call.
hintsThe original hints, exactly as passed to the getaddrinfo(3) system call.
resThe original res, exactly as passed to the getaddrinfo(3) system call.
Returns:
The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads.
Note:
This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library.
int explain_getaddrinfo_on_error ( const char *  node,
const char *  service,
const struct addrinfo *  hints,
struct addrinfo **  res 
)

The explain_getaddrinfo_on_error function is used to call the getaddrinfo(3) system call. On failure an explanation will be printed to stderr, but it still returns.

This function is intended to be used in a fashion similar to the following example:

 if (explain_getaddrinfo_on_error(node, service, hints, res))
 {
     ...handle error
     ...error message already printed
 }
Parameters:
nodeThe node, exactly as to be passed to the getaddrinfo(3) system call.
serviceThe service, exactly as to be passed to the getaddrinfo(3) system call.
hintsThe hints, exactly as to be passed to the getaddrinfo(3) system call.
resThe res, exactly as to be passed to the getaddrinfo(3) system call.
Returns:
This function only returns on success. On failure, prints an explanation and exits, it does not return.
void explain_getaddrinfo_or_die ( const char *  node,
const char *  service,
const struct addrinfo *  hints,
struct addrinfo **  res 
)

The explain_getaddrinfo_or_die function is used to call the getaddrinfo(3) system call. On failure an explanation will be printed to stderr, obtained from explain_errcode_getaddrinfo(3), and then the process terminates by calling exit(EXIT_FAILURE).

This function is intended to be used in a fashion similar to the following example:

 explain_getaddrinfo_or_die(node, service, hints, res);
Parameters:
nodeThe node, exactly as to be passed to the getaddrinfo(3) system call.
serviceThe service, exactly as to be passed to the getaddrinfo(3) system call.
hintsThe hints, exactly as to be passed to the getaddrinfo(3) system call.
resThe res, exactly as to be passed to the getaddrinfo(3) system call.
Returns:
This function only returns on success. On failure, prints an explanation and exits, it does not return.
void explain_message_errcode_getaddrinfo ( char *  message,
int  message_size,
int  errcode,
const char *  node,
const char *  service,
const struct addrinfo *  hints,
struct addrinfo **  res 
)

The explain_message_errcode_getaddrinfo function is used to obtain an explanation of an error returned by the getaddrinfo(3) system call. The least the message will contain is the value of gai_strerror(errcode), but usually it will do much better, and indicate the underlying cause in more detail.

This function is intended to be used in a fashion similar to the following example:

 int errcode = getaddrinfo(node, service, hints, res);
 if (errcode == EAI_SYSTEM)
     errcode = errno;
 if (errcode)
 {
     char message[3000];
     explain_message_errcode_getaddrinfo(message, sizeof(message),
         errcode, node, service, hints, res);
     fprintf(stderr, "%s\n", message);
     exit(EXIT_FAILURE);
 }
Parameters:
messageThe location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe.
message_sizeThe size in bytes of the location in which to store the returned message.
errcodeThe error value to be decoded, as returned by the getaddrinfo system call.
nodeThe original node, exactly as passed to the getaddrinfo(3) system call.
serviceThe original service, exactly as passed to the getaddrinfo(3) system call.
hintsThe original hints, exactly as passed to the getaddrinfo(3) system call.
resThe original res, exactly as passed to the getaddrinfo(3) system call.