scan_ip4(3)
π scan_ip4 β bestie edition π
okay so this one lives in the Library Functions Manual (yes, the whole libowfat crew π ), and it's genuinely one of my faves. let's get into it β¨
β¨ NAME β¨
scan_ip4 β parse an IPv4 number in dotted-decimal notation π¦
like. it reads a lil dotted-decimal IP string and turns it into actual bytes. that's the whole job. she's focused. she's iconic. π
πΈ SYNTAX πΈ
#include <libowfat/ip4.h>
int scan_ip4(const char *src,char ip[4]);
okay so you pull in the header, and then you get this one function. two args, one int back. simple. clean. we love a low-maintenance queen π
π DESCRIPTION π
so scan_ip4 parses an IPv4 number in dotted-decimal ASCII representation, reading it out of src, and then it writes the result into ip. that's it, that's the vibe. β¨
it returns the number of bytes read from src β or 0 if the parsing failed π so like, 0 is the "nope, didn't work" signal. do not ignore the 0. fr fr.
β οΈ and here's the thing, bestie, listen up: unlike many other IP parsing routines,scan_ip4does not recognize octal (like0177.0.0.1) or hexadecimal numbers (like0x7f000001). no hex, no octal, none of it. she is strictly dotted-decimal and she said what she said. periodt. π
π EXAMPLE π
#include <libowfat/str.h>
#include <libowfat/ip4.h>
char buf[]="160.45.40.10";
char ip[4];
if (scan_ip4(buf,ip) != str_len(buf))
parse_error();
see what she did there? π she compared the return value against str_len(buf) β because if scan_ip4 read every byte, then it ate the whole string and we're slaying. if the numbers don't match, parse_error(). that's the check, that's the move. π
π¦ SEE ALSO π¦
fmt_ip4(3)β the other direction, turning bytes back into a pretty string πscan_ip6(3)β her IPv6 sister, also serving looks β¨inet_pton(3)β the classic, the elder, respect her π«Ά
okay that's the whole page, bestie, you're so welcome π this one comes from the Library Functions Manual, it's scan_ip4(3) β go parse something cute with her. no cap. πΈπ
π
π¦ 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