explain_getaddrinfo(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

✨ 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 the errno global 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 of errno on you πŸ’€
  • node β€” the original node, exactly as it was passed to the getaddrinfo(3) system call. exact. same. energy.
  • 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 🌸

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 the errno global 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 of errno πŸ™ˆ
  • 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 πŸ’œ

🌈 SEE ALSO 🌈


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