fmt_ip6ifc(3)
π 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_ip6does 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 bestiefmt_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. ππβ¨
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms