fmt_ip6ifc(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_ip6ifc β€” bestie's guide to pretty IPv6 with a scope id πŸ’–

okay so this one is from fmt_ip6ifc(3), and it lives in the Library Functions Manual β€” yes the same fam as scan_ip6(3) and fmt_ip4(3), we'll get to them. sit down, hydrate, this is genuinely cute.


✨ NAME ✨

fmt_ip6ifc β€” writes out a formatted ASCII representation of an IPv6 number (with the interface/scope flavour, iykyk) πŸ¦‹


πŸŽ€ SYNTAX πŸŽ€

#include <libowfat/ip6.h>

unsigned int fmt_ip6ifc(char *dest,const char ip[16],uint32 scope_id);

πŸ’… DESCRIPTION πŸ’…

So fmt_ip6ifc takes your IPv6 number in ip and formats it into ASCII representation, then drops the result straight into dest. It hands you back the number of bytes it wrote. periodt.

Bestie, it will apply "::" compression to the output. the way that it just shortens it for you… iconic honestly.

If ip happens to be an IPv4-mapped IPv6 address, fmt_ip6ifc will output it as an IPv4 address instead. it's giving dual-stack realness. 🌈

If dest equals FMT_LEN (i.e. is zero), fmt_ip6ifc returns the number of bytes it would have written. so it's a little window-shopping mode β€” no bytes written, just a vibe check on the size. πŸ”₯

πŸ’€ important one: fmt_ip6 does not append \0. it will NOT null-terminate for you. you gotta handle that yourself, bestie, do not forget.

ip6.h defines the integer IP6_FMT to be big enough to contain every possible fmt_ip6 output plus \0. However, for fmt_ip6ifc you need to add 1 for the '%' and IF_NAMESIZE from <net/if.h> for the interface name. so like… extra room required, no cap. 🫢


🌸 EXAMPLE 🌸

#include <libowfat/ip6.h>

  char buf[IP6_FMT];
  char ip[16];
  scope_id sid;
  buf[fmt_ip6ifc(buf,ip,sid)]=0;

see how the =0 is doing the null-terminating by hand?? because we said it doesn't do it for you. main character energy, honestly. 😭


⭐ SEE ALSO ⭐

  • scan_ip6(3) β€” the other direction, the reverse bestie
  • fmt_ip4(3) β€” the IPv4 cousin, also iconic

and that's the whole page!! 🧚 this was fmt_ip6ifc(3) from the Library Functions Manual β€” go format something gorgeous, and remember to null-terminate. mwah. πŸ’œπŸ’–βœ¨