Routines for working with IP subnets?

Are there any library functions or frameworks for working with IPv4/IPv6 subnets or ranges? Ie. to check whether a particular IP is within a subnet, or whether a particular IP is a LAN address, etc?
Routines for working with IP subnets?
 
 
Q