libexplain
1.4.D001
|
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) |
explain getaddrinfo(3) errors
Definition in file getaddrinfo.h.
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); }
errnum | The error value to be decoded, as returned by the getaddrinfo(3) system call. |
node | The original node, exactly as passed to the getaddrinfo(3) system call. |
service | The original service, exactly as passed to the getaddrinfo(3) system call. |
hints | The original hints, exactly as passed to the getaddrinfo(3) system call. |
res | The original res, exactly as passed to the getaddrinfo(3) system call. |
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 }
node | The node, exactly as to be passed to the getaddrinfo(3) system call. |
service | The service, exactly as to be passed to the getaddrinfo(3) system call. |
hints | The hints, exactly as to be passed to the getaddrinfo(3) system call. |
res | The res, exactly as to be passed to the getaddrinfo(3) system call. |
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);
node | The node, exactly as to be passed to the getaddrinfo(3) system call. |
service | The service, exactly as to be passed to the getaddrinfo(3) system call. |
hints | The hints, exactly as to be passed to the getaddrinfo(3) system call. |
res | The res, exactly as to be passed to the getaddrinfo(3) system call. |
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); }
message | The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. |
message_size | The size in bytes of the location in which to store the returned message. |
errcode | The error value to be decoded, as returned by the getaddrinfo system call. |
node | The original node, exactly as passed to the getaddrinfo(3) system call. |
service | The original service, exactly as passed to the getaddrinfo(3) system call. |
hints | The original hints, exactly as passed to the getaddrinfo(3) system call. |
res | The original res, exactly as passed to the getaddrinfo(3) system call. |