fmt_ip4(3)
fmt_ip4 π β¨
okay so bestie, we're in the Library Functions Manual today and the vibe is IPv4 addresses, so let's get into it π
β¨ NAME β¨
fmt_ip4 β write a formatted ASCII representation of an IPv4 number π¦
β¨ SYNTAX β¨
#include <libowfat/ip4.h>
unsigned int fmt_ip4(char *dest,const char ip[4]);
like. that's it. that's the whole thing. iconic honestly π
β¨ DESCRIPTION β¨
so fmt_ip4 takes your IPv4 number in ip and formats it into the dotted-decimal ASCII representation β yk, the 1.2.3.4 look β and writes the result into dest. it then hands you back the number of bytes written. periodt π
now listen, there's a little trick here that's lowkey so useful: if dest equals FMT_LEN (i.e. it's zero), then fmt_ip4 doesn't write anything β it just returns the number of bytes it would have written. it's giving "lemme measure first, then commit" energy, and we love a girl who plans ahead π
important bestie:fmt_ip4does not append\0. it does NOT null-terminate for you. so if you want a cute lil C string you gotta add that terminator yourself, no cap π
and for convenience (slay), ip4.h defines the integer IP4_FMT to be big enough to contain every possible fmt_ip4 output plus \0. so like, that's your buffer size, use it, don't be out here guessing πΈ
β¨ EXAMPLE β¨
#include <libowfat/ip4.h>
char buf[IP4_FMT];
char ip[4];
buf[fmt_ip4(buf,ip)]=0;
see how she puts the =0 right there at buf[fmt_ip4(buf,ip)]? that's the null terminator handoff, main character behavior fr fr π
β¨ SEE ALSO β¨
scan_ip4(3)πfmt_ip6(3)πinet_ntop(3)π
and that's the whole page bestie π«Ά this was the fmt_ip4(3) entry from the Library Functions Manual, signed off with love, sparkles, and a lil fmt_ip4(3) at the bottom for the girlies π
βπ§
π¦ 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