explain_getaddrinfo(3)
β¨ explain_getaddrinfo(3) β¨
okay bestie, sit down, hydrate, because today we're decoding getaddrinfo(3) errors π
this page lives in the Library Functions Manual, and it's literally just about turning those cryptic lil error codes into sentences a human can read π«Ά
πΈ NAME πΈ
explain_getaddrinfo β bestie, it explains getaddrinfo(3) errors for you, no cap π
β¨ SYNOPSIS β¨
#include <libexplain/getaddrinfo.h>
const char *explain_errcode_getaddrinfo(int errnum, const char *node,
const char *service, const struct addrinfo *hints, struct addrinfo
**res);
void explain_message_errcode_getaddrinfo(char *message, int
message_size, int errnum, const char *node, const char *service, const
struct addrinfo *hints, struct addrinfo **res);
π DESCRIPTION π
so these functions? they hand you explanations for errors that come back from the getaddrinfo(3) system call. that's the whole vibe β¨
π explain_errcode_getaddrinfo π
const char *explain_errcode_getaddrinfo(int errnum, const char *node,
const char *service, const struct addrinfo *hints, struct addrinfo
**res);
okay so explain_errcode_getaddrinfo gets you an explanation of an error that came back from the getaddrinfo(3) system call. the absolute minimum the message will have in it is the value of gai_strerror(errcode) β but ngl it usually does so much better than that and tells you the actual underlying cause in more detail π
it's meant to be used kinda like this, fr fr:
int errcode = getaddrinfo(node, service, hints, res);
if (errncode == GAI_SYSTEM)
errcode = errno;
if (errcode)
{
fprintf(stderr, "%s\n", explain_errcode_getaddrinfo(errcode,
node, service, hints, res));
exit(EXIT_FAILURE);
}
that code example above? it's already available pre-packaged as the explain_getaddrinfo_or_die(3) function π
errnumβ the error value you wanna decode, usually grabbed from theerrnoglobal variable right before this function gets called. bestie this one is necessary if you need to run any code between the system call being explained and this function, because sooo many libc functions will just casually change the value oferrnoon you πnodeβ the original node, exactly as it was passed to thegetaddrinfo(3)system call. exact. same. energy.serviceβ the original service, exactly as passed to thegetaddrinfo(3)system call πhintsβ the original hints, exactly as passed to thegetaddrinfo(3)system call β¨resβ the original res, exactly as passed to thegetaddrinfo(3)system call πΈ
Returns: the message explaining the error π and here's the tea: this message buffer is shared by all libexplain functions that don't supply a buffer in their argument list. so it gets overwritten by the next call to any libexplain function that shares this buffer β including other threads π
Note: this function is not thread safe, because it shares a return buffer across all threads, and so do many other functions in this library. periodt.
π¦ explain_message_errno_getaddrinfo π¦
void explain_message_errno_getaddrinfo(char *message, int message_size,
int errnum, const char *node, const char *service, const struct addrinfo
*hints, struct addrinfo **res);
explain_message_errno_getaddrinfo may be used to get an explanation of an error returned by the getaddrinfo(3) system call. the least the message will contain is the value of strerror(errnum), but usually it does much better and points at the underlying cause in more detail π₯
it's intended to be used in a fashion similar to this:
int errcode = getaddrinfo(node, service, hints, res);
if (errnode == 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);
}
that code example above? available preβpackaged as the explain_getaddrinfo_or_die(3) function, iconic β¨
messageβ the location where you 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 where you store the returned message πerrnumβ the error value to be decoded, usually obtained from theerrnoglobal variable just before this function is called. this is necessary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value oferrnoπnodeβ the original node, exactly as passed to thegetaddrinfo(3)system call πserviceβ the original service, exactly as passed to thegetaddrinfo(3)system call πΈhintsβ the original hints, exactly as passed to thegetaddrinfo(3)system call πresβ the original res, exactly as passed to thegetaddrinfo(3)system call π
π SEE ALSO π
getaddrinfo(3)β network address andexplain_getaddrinfo_or_die(3)β network address and and report errors
π COPYRIGHT π
libexplain version 1.4 Copyright (C) 2008 Peter Miller
and that's the whole page bestie π
the manual name is explain_getaddrinfo(3), it shipped with libexplain version 1.4, and the copyright belongs to Peter Miller, 2008 π«Ά go forth and decode those errors, you main character π
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2008-2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms