scan_ip4(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

πŸ’– 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_ip4 does not recognize octal (like 0177.0.0.1) or hexadecimal numbers (like 0x7f000001). 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. πŸŒΈπŸ’…πŸŽ€