fmt_ip6(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(3) β€” from the Library Functions Manual πŸ’–

okay bestie, sit down, hydrate, and let me tell you about fmt_ip6, one of the little legends living in section 3 of the Library Functions Manual. it's giving "tiny function, huge glow-up" energy and honestly? we're obsessed. πŸ¦‹


✨ NAME ✨

fmt_ip6 β€” write a formatted ASCII representation of an IPv6 number πŸ’…


🌸 SYNTAX 🌸

#include <libowfat/ip6.h>

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

that's it. that's the whole vibe. two args, one return, no drama. πŸŽ€


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea, fr fr: fmt_ip6 takes your IPv6 number from ip and formats it into ASCII representation, then writes the result into dest. it returns the number of bytes written. iconic behavior, no notes. ✨

fmt_ip6 will apply "::" compression to the output β€” so yes, it's out here making your addresses shorter and cuter, lowkey a stylist. πŸ’‡β€β™€οΈ

if ip is an IPv4-mapped IPv6 address, fmt_ip6 will output the last 4 bytes as IPv4 number in dotted-decimal notation. the way it just switches formats mid-function? main character energy honestly. πŸ‘‘

if dest equals FMT_LEN (i.e. is zero), fmt_ip6 returns the number of bytes it would have written. not me asking "how big would this be?" and getting a real answer. 😭 that's a size query, bestie, and it slaps.

fmt_ip6 does not append \0.

⚠️ girl. listen. it does NOT append \0. you have to do that yourself. do not forget. i am begging you. πŸ™ˆ

for convenience, ip6.h defines the integer IP6_FMT to be big enough to contain every possible fmt_ip6 output plus \0. so that's your buffer size, no cap. πŸ”₯


🧚 EXAMPLE 🧚

#include <libowfat/ip6.h>

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

see that last line? buf[fmt_ip6(buf,ip)]=0; β€” the return value becomes the index where the \0 goes. it's a whole little choreography and it ate. πŸ’ƒβœ¨


🌈 SEE ALSO 🌈

the whole friend group, periodt. go say hi. 🫢


and that's the page, bestie!! this one came straight out of the Library Functions Manual, filed under fmt_ip6(3) β€” section 3, where all the library function girlies hang out. no version or date on this one, so i'm not gonna make one up, i'm not a liar. πŸ’€

slay, be safe, always write your null terminator, mwah πŸ’–πŸ’…πŸ¦‹βœ¨