libapa...pSubnet(3pm)

πŸ’– NAME πŸ’–

APR::IpSubnet β€” it's the Perl API for getting at APR's ip_subnet structures, bestie ✨

(also known as libapa...pSubnet(3pm) from the User Contributed Perl Documentation, if you're checking the receipts 🧾)


πŸ“œ Synopsis

use APR::IpSubnet ();

my $ipsub = APR::IpSubnet->new($pool, "127.0.0.1");
$ok = $ipsub->test($sock_addr);

okay so that's the whole vibe in four lines and honestly? iconic πŸ‘‘


🌸 Description

So a APR::IpSubnet object is literally just a range of IP addresses β€” IPv4, IPv6, both, whatever πŸ’…

And then you can take a socket connection and match it against that range, to test whether the IP it's coming from is inside or outside of it. That's the whole personality. No cap. πŸ¦‹


⭐ API ⭐

APR::IpSubnet provides the following functions and/or methods, bestie, and we're going through all of them because nobody gets left behind 🫢

✨ new

Create an IP subnet representation object ✨

$ipsubnet = APR::IpSubnet->new($pool, $ip);
$ipsubnet = APR::IpSubnet->new($pool, $ip, $mask_or_numbits);
  • obj: APR::IpSubnet (class name)
  • arg1: $pool β€” an APR::Pool object 🏊
  • arg2: $ip (string) β€” the IP address, and it comes in one of two formats:
    • IPv4 (e.g. "127.0.0.1")
    • IPv6 (e.g. "::1")
heads up bestie: IPv6 addresses are accepted only if APR has the IPv6 support enabled πŸ’€ don't come for me when it doesn't work, that's just the rule
  • opt arg3: $mask_or_numbits (string) β€” optional, it's either an IP mask (e.g. "255.0.0.0") or a number of bits (e.g. "15"). If you don't provide one, the default is not to mask off, so like, don't mask off, live your truth 🌈
  • ret: $ret (APR::IpSubnet object) β€” the IP-subnet object, there she is πŸŽ€
  • excpt: APR::Error
  • since: 2.0.00

🧚 test

Test the IP address in the socket address object against a pre-built ip-subnet representation. Like a vibe check but for IPs πŸ”

$ret = $ipsub->test($sockaddr);
  • obj: $ipsub (APR::IpSubnet object) β€” the ip-subnet representation
  • arg1: $sockaddr (APR::SockAddr object) β€” the socket address you're testing
  • ret: $ret (boolean) β€” true if the socket address is within the subnet, false otherwise
  • since: 2.0.00

This method is used for testing whether or not an address is within a subnet. It's used by module mod_access to check whether the client IP fits into the IP range, supplied by Allow/Deny directives. iykyk πŸ’…

Example:

Allow accesses only from the localhost (IPv4) 🌸:

use APR::IpSubnet ();
use Apache2::Connection ();
use Apache2::RequestRec ();
my $ipsub = APR::IpSubnet->new($r->pool, "127.0.0.1");
ok $ipsub->test($r->connection->remote_addr);

πŸ‘€ See Also

mod_perl 2.0 documentation. go read it, it's giving✨


mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.


πŸ‘‘ Authors

The mod_perl development team and numerous contributors. πŸ’œ


and that's the whole page, bestie!! 🌈 this was from perl v5.42.3, dated 2026-08-20 β€” slay, mwah, drink some water, and go subnet something responsibly πŸ«ΆπŸ’–πŸŽ€

πŸ“¦ where this page comes from