LC_SHARE(3)

πŸ“¦
version 0.11.2 Β· 2 versions
, in nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

πŸ’– LC_SHARE(3) β€” ok bestie, let's talk sharing πŸ’–

So this is lc_share and lc_unshare from the Librecast programmer's manual, and they do exactly what it says on the tin: share and unshare files over multicast. No cap. πŸ¦‹


πŸ“š LIBRARY

Librecast library (liblibrecast, -llibrecast). That's your girl. πŸ’…


✨ SYNOPSIS ✨

#include <librecast/net.h>

lc_share_t *lc_share(lc_ctx_t *lctx, mdex_t *mdex, unsigned int ifx,
                lc_stat_t *stats, lc_sync_options_t *opt, int flags);
void lc_unshare(lc_share_t *share);

lc_share_t *lc_share_acquire(lc_share_t *share);
void lc_share_release(lc_share_t *share);

And like, when you actually build the thing: compile and link with -llibrecast. Periodt. πŸŽ€


🌸 DESCRIPTION 🌸

Okay so lc_share takes the objects that are indexed in mdex and shares them on the interface you pass in as ifx. And here's the cute part: if ifx is zero, the files get shared on all multicast-capable interfaces. Everything, everywhere, all at once, iykyk. 🌈

lc_share kicks off MLD snooping (that's IETF RFC 3810, for the girlies keeping receipts πŸ“). When it detects a join on a new IPv6 multicast group, that join gets checked against the index that mdex gave you. Found a matching object? It goes straight into the sending queue, and the data for that object just keeps on sending until MLD reports there are no more listeners for that group. She's committed, fr fr. πŸ’–

The data being sent is encoded using RaptorQ Forward Error Correction (IETF RFC 6330), via the LCRQ library. Iconic error correction behaviour, honestly.

If stats is not NULL, the transfer statistics get returned in that structure. Free numbers, bestie. πŸ“Š

opt is not used at present, and it must be NULL for compatibility with future versions. Don't get cute with it. πŸ™ˆ

The flags argument is the bitwise OR of zero or more of these bad boys:

  • LC_SHARE_LOOPBACK β€” sets the loopback option IPV6_MULTICAST_LOOP on the sending socket. That's the whole vibe of this flag. ✨

Now for the reader-count girlies:

lc_share_acquire increments the reader count on the share object. That object will not be freed until the reader count hits zero. Super useful for keeping track of readers in a multithreaded program β€” main character bookkeeping energy. πŸ‘‘

lc_share_release decrements the reader count on the share object. And if the number of readers is zero? She gets freed. Bye bestie πŸ’€


🫢 RETURN VALUE 🫢

lc_share() returns a pointer to a lc_share_t handle, and you should free it by passing it to lc_unshare() when you're done. On error, NULL comes back, and errno is set to tell you what went wrong.

The lc_unshare() function returns no value, and it preserves errno. Respectful. We love a function that doesn't mess with your error state. πŸŽ€


πŸ’€ ERRORS πŸ’€

  • ENOTSUP β€” lc_share() is not supported with your current configuration. This one pops up when the librecast library was built without MLD support. Tragic, honestly.
  • ENOMEM β€” Not enough space/cannot allocate memory (POSIX.1-2001). The memory said no. 😭
  • EACCES β€” Permission to create a socket of the specified type and/or protocol is denied. Rude, but valid.

🧚 NOTES 🧚

lc_share uses MLD snooping from libmld to detect which multicast groups are active, and that uses a raw socket. So listen up:

On Linux, creating a raw socket requires CAP_NET_RAW. See Capabilities(7). On *BSD the creation of a raw socket is restricted to the superuser. An application can drop these privileges after calling lc_share.

So like, get your permissions, do the thing, then drop the privileges. Glow up and let go. πŸ¦‹

And if you wanna restrict syncing to one particular network interface? Call lc_ctx_ifx(3) to set the default interface for the Librecast context before you call the appropriate sync function. Order matters, bestie, don't skip steps. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

lc_ctx_new(3), lc_ctx_ifx(3), mdex_init(3), mdex_get(3), mdex_put(3), mdex_del(3), lcrq(7)

Go read those too, they're all part of the same little universe. 🌸


LIBRECAST Β· 2025-06-09 β€” that's the source and the date, babes, shoutout to the Librecast girlies for shipping this on June 9th 2025. Stay slay, stay multicast. β­πŸŽ€βœ¨

πŸ“¦ where this page comes from