#!/usr/bin/env awk
#
# Return true if 'ip' is a private IPv4 address.
#
# Private IPv4 addresses:
#   - 10.0.0.0/8
#   - 172.16.0.0/12
#   - 192.168.0.0/16
#
# Parameters:
#   - ip : the IPv4 address to test
#
# Dependencies:
#   - None
#
# Examples:
#   - tawk 'privip($srcIP)' file.txt
#   - tawk '!privip($dstIP) { print }' file.txt

@include "hdr"
@include "ipinnet"

function privip(ip) {
    return ipinnet(ip, "10.0.0.0/8")     ||
           ipinnet(ip, "172.16.0.0/12")  ||
           ipinnet(ip, "192.168.0.0/16") ||
           (__PRIHDR__ && hdr())
}
