fmt_ip6_flat(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– fmt_ip6_flat(3) πŸ’–

okay so bestie, welcome to the Library Functions Manual β€” this is the page for fmt_ip6_flat, and it's genuinely such a useful little icon, no cap. Let's get into it 🫢


✨ NAME ✨

fmt_ip6_flat β€” write a formatted ASCII representation of an IPv6 number


🌸 SYNTAX 🌸

#include <libowfat/ip6.h>

unsigned int fmt_ip6_flat(char *dest,const char ip[16]);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: fmt_ip6_flat takes an IPv6 number from ip and formats it into a flat ASCII representation, then writes the result straight into dest. It hands you back the number of bytes it wrote, which is always 32. Always. Every time. Periodt πŸ’…

This representation has no colons in it at all, which is the whole point β€” it's designed to be easily machine-readable. If you want the normal, standard, everyone-knows-it representation, go use fmt_ip6 instead. This one is for those specific places that use colons to separate their own fields and therefore get all confused trying to interpret the standard IPv6 notation. Not their fault, but here we are πŸ™ˆ

And listen β€” if dest equals FMT_LEN (basically, if it's zero), then fmt_ip6_flat returns the number of bytes it would have written. So it's giving you a little preview, a little "here's how much space you'd need" moment ✨

Heads up bestie: fmt_ip6_flat does not append \0. It's not gonna null-terminate anything for you. That's on you πŸ’€

Oh and for convenience β€” because the devs love us β€” ip6.h defines the integer IP6_FMT to be big enough to hold every possible fmt_ip6_flat output, plus the \0. So you can just use that for your buffer size and not stress about it 🌈


πŸŽ€ EXAMPLE πŸŽ€

#include <libowfat/ip6.h>

  char buf[IP6_FMT];
  char ip[16];
  buf[fmt_ip6_flat(buf,ip)]=0;

See how it writes the result and then we slap a 0 right where the function's return value points? That's the move. Slay πŸ”₯


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie πŸ’œ go forth and format your IPv6 addresses flat and colon-free, you absolute main character. this was the fmt_ip6_flat(3) page from the Library Functions Manual β€” footer said fmt_ip6_flat(3) and honestly? iconic. bye πŸŽ€βœ¨πŸ¦‹