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 for libcidr is 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 a CIDR structure describing the broadcast address of the network represented by cidr. the loud one. πŸ“’
  • CIDR *cidr_addr_hostmax(const CIDR *cidr) β€” returns a CIDR structure describing the "highest" host in the subnet represented by cidr. top of the class, literally. ⭐
  • CIDR *cidr_addr_hostmin(const CIDR *cidr) β€” returns a CIDR structure describing the "lowest" host in the subnet represented by cidr. humble queen. πŸ™ˆ
  • CIDR *cidr_addr_network(const CIDR *cidr) β€” returns a CIDR structure describing the network address of the network represented by cidr. the main character of the subnet, honestly. πŸ’œ

🧚 memory girlies

  • CIDR *cidr_alloc(void) β€” allocate and initialize a CIDR structure. brand new, fresh out the box. ✨
  • CIDR *cidr_dup(const CIDR *cidr) β€” return a duplicate of cidr. twin where? twin here. πŸ‘―
  • void cidr_free(CIDR *cidr) β€” free the memory used by a CIDR *. she's done, let her rest. πŸ’€

πŸ¦‹ comparisons & checks

  • int cidr_contains(const CIDR *big, const CIDR *little) β€” determine whether little is a CIDR block entirely contained within the block described by big. returns 0 if so, else non-zero. big sister energy fr. 🫢
  • int cidr_equals(const CIDR *first, const CIDR *second) β€” determine whether first and second describe the same CIDR block. returns 0 if 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 a CIDR * based on a struct in_addr.
  • CIDR *cidr_from_in6addr(const struct in6_addr *in) β€” generate a CIDR * based on a struct in6_addr.
  • CIDR *cidr_from_str(const char *str) β€” parse str and return a CIDR * 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 of cidr.
  • 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 of CIDR *'s representing the two immediate subnets of the network described by cidr. that is to say, the two networks, within cidr, which have a netmask 1 bit longer. her two little babies. 🍼
  • CIDR *cidr_net_supernet(const CIDR *cidr) β€” return a CIDR * describing the "parent" network of cidr. that is, the network with a netmask 1 bit shorter, which wholly contains cidr. 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 by cidr. do not attempt to alter or free(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 of pflen. do not attempt to alter or free(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 by cidr. do not attempt to alter or free(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 of pflen. do not attempt to alter or free(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 a struct in_addr with the address given in cidr. a user-supplied struct in_addr is 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 a struct in6_addr with the address given in cidr. a user-supplied struct in6_addr is 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-in cidr, as described by flags. by default, it will print in the standard address form for whatever address family cidr represents, followed by a slash, and then the prefix length of the netmask. she's giving address/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 πŸ‘‘βœ¨