MDEX_GET(3)

✨ NAME ✨

mdex_get β€” bestie, this is how you pull an entry out of a multicast index πŸ’–


πŸ“š LIBRARY πŸ“š

The Librecast library, aka liblibrecast, and you link it with -llibrecast 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <librecast/mdex.h>

int mdex_get(mdex_t *mdex, unsigned char *hash, size_t hashlen, mdex_entry_t *entry);
int mdex_getalias(mdex_t *mdex, const char *path, mdex_entry_t *entry);

Compile and link with -llibrecast. No cap. ✨


πŸ’… DESCRIPTION πŸ’…

Okay so, mdex_get grabs an entry from the multicast index mdex, using hash (of length hashlen) as the key, and it drops a copy of the data into entry if you actually handed it one. And if entry is NULL? That's totally fine, girl β€” the return value still lets you check whether an entry even exists in the index without retrieving it. A little peek, no commitment. πŸ‘‘

If there's no matching entry in the index, -1 comes back and errno gets set to ENOENT. Sad but true. 😭

Here's the iconic part: hashlen can be shorter than the full length of the hash you stored with mdex_put(3), and it'll return the first entry matching that truncated hash. The way that works is so smart β€” it means we can store the full 32 byte hash in the index, but still match against a truncated hash derived from, like, the 14 bytes of an IPv6 multicast group address. Fr fr. 🌸

Then there's mdex_getalias(), which is just a little wrapper bestie that calls mdex_get() with the hash of the NUL-terminated string path, and returns the result. She's lowkey just doing the legwork for you. πŸ’œ


🌈 RETURN VALUE 🌈

mdex_get() returns zero on success. ✨ On error, -1 is returned, and errno is set to tell you what went wrong.


πŸ’€ ERRORS πŸ’€

  • EINVAL β€” Invalid argument. Both mdex and hash are required (not NULL), and hashlen > 0. You gotta give her something to work with.
  • ENOENT β€” No entry found matching hash. She looked. It's not there. πŸ™ˆ
  • ELOOP β€” Infinite loop. Alias points to itself. Not the alias eating itself, bestie, we don't do that here. 🚫

πŸ‘‘ SEE ALSO πŸ‘‘

mdex_init(3), mdex_free(3), mdex_put(3), mdex_del(3), lc_share(3)


That's a wrap, queen πŸ’– This page is from the Librecast Programmer's Manual, dated 2023-06-20, brought to you by LIBRECAST β€” go forth and retrieve those entries, iykyk πŸ¦‹β­

πŸ“¦ where this page comes from