libcidr(3)
π libcidr(3) β Library Functions Manual π
okay bestie, pull up a chair, because we're about to talk about libcidr β the C library that does CIDR-style IP address manipulation, and honestly? she's iconic. β¨
β¨ NAME β¨
libcidr β CIDR-style IP address manipulation functions π¦
πΈ SYNOPSIS πΈ
#include <libcidr.h>
Library libcidr (-lcidr)
π SUMMARY π
so like, libcidr is a C library that implements a whole bunch of functions to manipulate IP addresses and netblocks. she handles both IPv4 and IPv6 networks, will transform them to and from text strings in a variety of formats, cram them into and lever them out of in_addr and in6_addr structures, and give you all sorts of stats about them. lowkey a multitasker. π
there are also functions provided to tell you a few things about the network any given CIDR block is in, what its parent and child networks are, and so on. and if you're really nice, libcidr may even cook you breakfast. π³ no cap.
okay but fr fr β the primary documentation forlibcidris maintained elsewhere, with a full description of the functions, their options, and their return values. your installation probably has a copy of the reference manual installed somewhere, perhaps in/usr/share/libcidr/docs. documentation is also available on the webpage (see below, babes π). this manpage is provided as a quick reference. don't come for her.
π DESCRIPTION OF FUNCTIONS π
π«Ά the ones that tell you about addresses
CIDR *cidr_addr_broadcast(const CIDR *cidr)β returns aCIDRstructure describing the broadcast address of the network represented bycidr. the loud one. π’CIDR *cidr_addr_hostmax(const CIDR *cidr)β returns aCIDRstructure describing the"highest"host in the subnet represented bycidr. top of the class, literally. βCIDR *cidr_addr_hostmin(const CIDR *cidr)β returns aCIDRstructure describing the"lowest"host in the subnet represented bycidr. humble queen. πCIDR *cidr_addr_network(const CIDR *cidr)β returns aCIDRstructure describing the network address of the network represented bycidr. the main character of the subnet, honestly. π
π§ memory girlies
CIDR *cidr_alloc(void)β allocate and initialize aCIDRstructure. brand new, fresh out the box. β¨CIDR *cidr_dup(const CIDR *cidr)β return a duplicate ofcidr. twin where? twin here. π―void cidr_free(CIDR *cidr)β free the memory used by aCIDR *. she's done, let her rest. π
π¦ comparisons & checks
int cidr_contains(const CIDR *big, const CIDR *little)β determine whetherlittleis a CIDR block entirely contained within the block described bybig. returns0if so, else non-zero. big sister energy fr. π«Άint cidr_equals(const CIDR *first, const CIDR *second)β determine whetherfirstandseconddescribe the same CIDR block. returns0if they do, else non-zero. are they the same person? πint cidr_is_v4mapped(const CIDR *addr)β checks if an IPv6 address is in the IPv4-mapped range. identity crisis check. πͺ
π conversion girlies (in)
CIDR *cidr_from_inaddr(const struct in_addr *in)β generate aCIDR *based on astruct in_addr.CIDR *cidr_from_in6addr(const struct in6_addr *in)β generate aCIDR *based on astruct in6_addr.CIDR *cidr_from_str(const char *str)β parsestrand return aCIDR *representing it. glow up from string to struct. π
π getters, we love a getter
uint8_t *cidr_get_addr(const CIDR *cidr)β return the address in an array of binary octets.uint8_t *cidr_get_mask(const CIDR *cidr)β return the netmask in an array of binary octets.int cidr_get_pflen(const CIDR *cidr)β return the length of the netmask prefix ofcidr.int cidr_get_proto(const CIDR *cidr)β return the protocol of an address.
πΈ network family tree
CIDR **cidr_net_subnets(const CIDR *cidr)β return a 2-element array ofCIDR *'s representing the two immediate subnets of the network described bycidr. that is to say, the two networks, withincidr, which have a netmask 1 bit longer. her two little babies. πΌCIDR *cidr_net_supernet(const CIDR *cidr)β return aCIDR *describing the"parent"network ofcidr. that is, the network with a netmask 1 bit shorter, which wholly containscidr. mother is mothering. π
π the number girlies (static strings, do NOT touch)
const char *cidr_numaddr(const CIDR *cidr)β return a pointer to a static string giving the number of total addresses available in the network described bycidr. do not attempt to alter orfree(3)this string. π¨const char *cidr_numaddr_pflen(int pflen)β return a pointer to a static string giving the number of total addresses available in a network having a prefix length ofpflen. do not attempt to alter orfree(3)this string. you probably don't want to call this function manually often. like, she's for the internal girlies, iykyk. πconst char *cidr_numhost(const CIDR *cidr)β return a pointer to a static string giving the number of addresses available for hosts available in the network described bycidr. do not attempt to alter orfree(3)this string. π¨const char *cidr_numhost_pflen(int pflen)β return a pointer to a static string giving the number of addresses available for hosts in a network having a prefix length ofpflen. do not attempt to alter orfree(3)this string. you probably don't want to call this function manually often. same deal bestie. π
π§ conversion girlies (out)
struct in_addr *cidr_to_inaddr(const CIDR *cidr, struct in_addr *in)β fill in astruct in_addrwith the address given incidr. a user-suppliedstruct in_addris used if passed in; if a null pointer is passed, a new one will be allocated, filled in, and returned. choose your own adventure. β¨struct in6_addr *cidr_to_in6addr(const CIDR *cidr, struct in6_addr *in)β fill in astruct in6_addrwith the address given incidr. a user-suppliedstruct in6_addris used if passed in; if a null pointer is passed, a new one will be allocated, filled in, and returned. same vibe, v6 edition. πchar *cidr_to_str(const CIDR *cidr, int flags)β return a string version of the passed-incidr, as described byflags. by default, it will print in the standard address form for whatever address familycidrrepresents, followed by a slash, and then the prefix length of the netmask. she's givingaddress/pflen. π₯
β the vibe check
const char *cidr_version(void)β return a static string containing version information. who is she? π
π AUTHOR π
libcidr is written and maintained by Matthew Fuller β¨fullermd@over-yonder.netβ©. its home on the web is at β¨http://www.over-yonder.net/~fullermd/projects/libcidrβ©; check there for updates and additional documentation. π«Ά
and that's the whole page bestie, no cap, every single function accounted for π
Debian Β· May 7, 2012 Β· libcidr(3) β mwah, go forth and manipulate your netblocks, queen πβ¨
π¦ where this page comes from
- debian bookworm: libcidr-dev 1.2.3-3 Β· BSD-2-Clause
- debian trixie: libcidr-dev 1.2.3-3+b2 Β· BSD-2-Clause
- ubuntu jammy: libcidr-dev 1.2.3-3 Β· BSD-2-Clause
- ubuntu noble: libcidr-dev 1.2.3-3 Β· BSD-2-Clause
- ubuntu resolute: libcidr-dev 1.2.3-3build1 Β· BSD-2-Clause
- ubuntu stonking: libcidr-dev 1.2.3-3build1 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms