Fast RFC-strict IPv4/IPv6 address arithmetic, CIDR manipulation, bulk prefix operations, and LPM indexing
Project description
libcidr
libcidr is a C11 library and CPython extension for strict IPv4/IPv6 address arithmetic, CIDR manipulation, bulk prefix operations, longest-prefix-match indexing, and IANA special-purpose address classification. It does not do routing protocol logic, network I/O, DNS resolution, or operational routability inference beyond the documented classification flags. Designed for Python users hitting pure-Python performance limits; see bench/BASELINES.md for measured comparisons against ipaddress, netaddr, and pytricia.
Build Requirements
- libc
- Clang or GCC
- CPython 3.11 or newer for the Python binding
Build And Install
C Library
make
make install
This builds libcidr.a and installs:
libcidr.ainto$(PREFIX)/liblibcidr.hinto$(PREFIX)/include
Python Binding
If installing from PyPI:
pip install libcidr
If building from source:
make python-ext
make python-install
Minimal C Example
#include <stdio.h>
#include <libcidr.h>
int
main(void)
{
cidr_addr_t addr;
cidr_prefix_t prefix;
cidr_class_t cls;
bool contains;
cidr_err_t rc;
rc = cidr_addr_parse("192.168.1.10", &addr);
if (rc != CIDR_OK)
return 1;
rc = cidr_addr_classify(&addr, &cls);
if (rc != CIDR_OK)
return 1;
rc = cidr_prefix_parse("192.168.1.0/24", &prefix);
if (rc != CIDR_OK)
return 1;
rc = cidr_prefix_contains(&prefix, &addr, &contains);
if (rc != CIDR_OK)
return 1;
printf("private=%s contains=%s\n",
(cls & CIDR_CLASS_PRIVATE) ? "yes" : "no",
contains ? "yes" : "no");
return 0;
}
Build example:
cc -std=c11 -I/usr/local/include example.c -L/usr/local/lib -lcidr -o example
./example
# output: private=yes contains=yes
Minimal Python Example
import libcidr
addrs = [
libcidr.IPv4Address("10.1.2.3"),
libcidr.IPv4Address("203.0.113.10"),
]
prefixes = [
libcidr.IPv4Network("10.0.0.0/8"),
libcidr.IPv4Network("192.168.0.0/16"),
]
print(libcidr.bulk_contains(addrs, prefixes))
# [0, -1]
Known Limitations
- No network I/O
- No DNS resolution
CIDR_CLASS_GLOBALmeans no special-purpose block matched; it does not imply real-world routability
Design Rationale
See ARCHITECTURE.md for the full design rationale and internal specification.
License
ISC License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libcidr-1.0.1.tar.gz.
File metadata
- Download URL: libcidr-1.0.1.tar.gz
- Upload date:
- Size: 67.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7cc6327d413b29b98e8be042214efa4cf3aacba51b32ea5549fabec9d8a1145
|
|
| MD5 |
ee2a2ade7b15791dab230011029ef160
|
|
| BLAKE2b-256 |
263e7eee51ec55cbc63d003682578f92aad7ecab6cadd67f8b1c79bafb03d04d
|
Provenance
The following attestation bundles were made for libcidr-1.0.1.tar.gz:
Publisher:
release.yml on pawelzelawski/libcidr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libcidr-1.0.1.tar.gz -
Subject digest:
c7cc6327d413b29b98e8be042214efa4cf3aacba51b32ea5549fabec9d8a1145 - Sigstore transparency entry: 1783511266
- Sigstore integration time:
-
Permalink:
pawelzelawski/libcidr@de2570a0e90821e181ed65657d85e2fd9d00506b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/pawelzelawski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de2570a0e90821e181ed65657d85e2fd9d00506b -
Trigger Event:
push
-
Statement type:
File details
Details for the file libcidr-1.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: libcidr-1.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 119.7 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99a0df2c5f3c8105b91216062f33d9451f36b44c22f37390470c345e12ff5122
|
|
| MD5 |
3ef1b614c3d559c6aaeca33b70d6e054
|
|
| BLAKE2b-256 |
716779f75b90b1b9b3c753553c0236b64116c7785715d92ff4062993790af6c5
|
Provenance
The following attestation bundles were made for libcidr-1.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on pawelzelawski/libcidr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libcidr-1.0.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
99a0df2c5f3c8105b91216062f33d9451f36b44c22f37390470c345e12ff5122 - Sigstore transparency entry: 1783511422
- Sigstore integration time:
-
Permalink:
pawelzelawski/libcidr@de2570a0e90821e181ed65657d85e2fd9d00506b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/pawelzelawski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de2570a0e90821e181ed65657d85e2fd9d00506b -
Trigger Event:
push
-
Statement type:
File details
Details for the file libcidr-1.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: libcidr-1.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 122.2 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01a9ca5effb8bcf0e56e11a1cf1f69b5bd9cc098bc3eb3eaacecd1cdc7831a42
|
|
| MD5 |
6de3d9bd38e9d1cf010a4840250491a6
|
|
| BLAKE2b-256 |
41ca5cc89cfb701923dd640837d08c36e68219c3935855d0a3a3038c71b84e95
|
Provenance
The following attestation bundles were made for libcidr-1.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on pawelzelawski/libcidr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libcidr-1.0.1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
01a9ca5effb8bcf0e56e11a1cf1f69b5bd9cc098bc3eb3eaacecd1cdc7831a42 - Sigstore transparency entry: 1783511536
- Sigstore integration time:
-
Permalink:
pawelzelawski/libcidr@de2570a0e90821e181ed65657d85e2fd9d00506b -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/pawelzelawski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@de2570a0e90821e181ed65657d85e2fd9d00506b -
Trigger Event:
push
-
Statement type: