scan_ip6(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_ip6 β€” ok bestie, let's talk IPv6 parsing ✨

so this lil guy lives in the Library Functions Manual, section 3 (that's the libowfat crew, iykyk πŸ’…). its whole job? taking an IPv6 address written out as text and turning it into actual bytes. periodt.


🌸 NAME 🌸

scan_ip6 β€” parse an IPv6 number in ASCII representation πŸ¦‹


πŸ’– SYNTAX πŸ’–

#include <libowfat/ip6.h>

int scan_ip6(const char *src,char ip[16]);

πŸ‘‘ DESCRIPTION πŸ‘‘

ok so scan_ip6 parses an IPv6 number in RFC1884 ASCII representation from src and writes the result into ip. she returns the number of bytes she read from src, or 0 if the parsing failed 😭 (yes, zero means it did NOT go well, that's your red flag).

she's lowkey flexible too:

  • she accepts upper and lower case hex letters (no judgment, both slay)
  • she understands "::" compression πŸ’«
  • she understands partial IPv4 addresses, like "::FFFF:129.144.52.38"

and here's the iconic part β€” to allow transparent usage of IPv4 in IPv6 applications, scan_ip6 also understands IPv4 addresses in dotted-decimal notation and will return an IPv4-mapped IPv6 address. so like, "127.0.0.1" gets parsed as "::FFFF:127.0.0.1" 🫢

⚠️ but bestie, listen: unlike many other IP parsing routines, scan_ip6 does not recognize octal (like 0177.0.0.1) or hexadecimal numbers (like 0x7f000001) in the IPv4 part. no cap. don't try it. she's not doing that.

🌈 EXAMPLE 🌈

#include <libowfat/str.h>
#include <libowfat/ip6.h>

  char buf[]="::1";
  char ip[16];
  if (scan_ip6(buf,ip) != str_len(buf))
    parse_error();

see how she compares the return value to str_len(buf)? that's the vibe check β€” if they don't match, parse_error() time πŸ™ˆ


πŸŽ€ SEE ALSO πŸŽ€


and that's the whole page, bestie πŸ’œ shoutout to the Library Functions Manual and the scan_ip6(3) section-3 girlies for keeping our IPv6 parsing cute and correct βœ¨πŸ¦‹ no thoughts, just bytes 🫢