Skip to content

Commit 98ffd49

Browse files
authored
README fixes
1 parent 3142abd commit 98ffd49

1 file changed

Lines changed: 46 additions & 58 deletions

File tree

README.md

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<div align="center">
32

43
<img src="cidre.png" alt="CIDRE logo" width="444" height="88" />
@@ -12,54 +11,52 @@
1211
[![Kotlin](https://img.shields.io/badge/kotlin-2.2.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
1312
[![Java](https://img.shields.io/badge/java-17-blue.svg?logo=OPENJDK)](https://www.oracle.com/java/technologies/downloads/#java17)
1413
[![Android](https://img.shields.io/badge/Android-SDK--21-37AA55?logo=android)](https://developer.android.com/tools/releases/platforms#5.0)
15-
[![Maven Central](https://img.shields.io/maven-central/v/at.asitplus/cidre)](https://mvnrepository.com/artifact/at.asitplus.maven/coordinates)
14+
[![Maven Central](https://img.shields.io/maven-central/v/at.asitplus/cidre)](https://mvnrepository.com/artifact/at.asitplus/cidre)
1615

1716
</div>
1817

1918

20-
> From orchard to endpoint: _CIDRE_ delivers a smooth, dry balance of IP handling and subnet math, served consistently
19+
> From orchard to endpoint: _CIDRE_ delivers a smooth, dry balance of IP handling and subnet math, served consistently
2120
> sparkling across **all** KMP targets. Unchaptalized&hairsp;&mdash;&hairsp;zero added dependencies; just natural, refreshing clarity.
2221
23-
&mdash; _Sir Evander Marchbank_, self-proclaimed cider cartographer who insists that every orchard has its own “gravitational pull” affecting the bubbles.
22+
&mdash; _Sir Evander Marchbank_, self-proclaimed cider cartographer, who insists that every orchard has its own “gravitational pull” affecting the bubbles.
2423

2524
---
2625

27-
CIDRE focuses on parsing and representing IP addresses, IP networks and providing CIDR math. On the JVM and Android it maps from/to `InetAddress`/`Inet4Address`/`Inet6Address`. On native targets, it maps from/to `in_addr`/`in6_addr`.
28-
It is not a full IP networking implementation, but you can use it to implement IP routing.
29-
It has a total of zero external dependencies.
26+
CIDRE focuses on parsing and representing IP addresses, IP networks, and performing CIDR math. On the JVM and Android it maps from/to `InetAddress`/`Inet4Address`/`Inet6Address`. On native targets, it maps from/to `in_addr`/`in6_addr`.
27+
It is not a full IP networking implementation, but you can use it to implement IP routing.
28+
It has exactly zero external dependencies.
29+
3030
Currently, CIDRE provides the following functionality:
31-
* parsing and encoding IPv4 and IPv6 addresses from/to String and ByteArray representations
31+
* parsing and encoding IPv4 and IPv6 addresses from/to `String` and `ByteArray` representations
3232
* converting CIDR prefixes from/to netmasks
33-
* checking whether addresses or networks are are fully contained within a network
34-
* comparability of networks and addresses inside a family (IPv4/IPv6)
33+
* checking whether addresses or networks are fully contained within a network
34+
* comparing networks and addresses within the same family (IPv4/IPv6)
3535

36-
Planned features are:
36+
Planned features include:
3737
* iterating over, slicing, splitting, and merging networks
3838
* subnetting and supernetting
3939

40-
41-
In general, CIDRE's data model has semantics influenced by [netaddr](https://github.com/netaddr/netaddr/?tab=readme-ov-file): An `IpNetwork` covers a range of `IpInterface`s, both of which consist of an `IpAddress` and a `prefix`.
40+
In general, CIDRE's data model has semantics influenced by [netaddr](https://github.com/netaddr/netaddr/?tab=readme-ov-file): An `IpNetwork` covers a range of `IpInterface`s, both of which consist of an `address` and a `prefix`.
4241
Semantically, an `IpInterface` has only a single `IpAddress` (although no validation is performed whether it is distinct from the associated network's address), while a network spans a range.
4342
In more technical terms, CIDRE introduces three main classes:
44-
- `IpAddress` - a sealed class, specialised as
45-
- `IpAddress.V4` representing IPv4 addresses
46-
- `IpAddress.V6` representing IPv6 addresses
47-
- `IpNetwork` - a sealed class, following the same hierarchy:
48-
- `IpNetwork.V4` representing an IPv4 network consisting of an `IpAddress.V4` network address and a prefix/netmask
49-
- `IpNetwork.V6` representing an IPv4 network consisting of an `IpAddress.V6` network address and a prefix/netmask
50-
- `IpInterface` a concrete IP address belonging to a network. Like a network, this is also a combination of IP address and prefix/netmask but with distinctly different semantics.
51-
- `IpInterface.V4` consisting of an `IpAddress.V4` network address and a prefix/netmask
52-
- `IpInterface.V6` consisting of an `IpAddress.V6` network address and a prefix/netmask
53-
54-
`IpNetwork`, `IpAddress` and their IPv4 and IPv6 specializations share the `IpAddressAndPrefix` interface hierarchy, which groups common semantics and functionality.
55-
However, addresses and networks are not comparable, so this is mainly an application of DRY.
56-
In addition, two typealiases are used:
57-
* `typealias Prefix = UInt`
58-
* `typealias Netmask = ByteArray`.
43+
- `IpAddress` — a sealed class, specialized as:
44+
- `IpAddress.V4` representing IPv4 addresses
45+
- `IpAddress.V6` representing IPv6 addresses
46+
- `IpNetwork` — a sealed class, following the same hierarchy:
47+
- `IpNetwork.V4` representing an IPv4 network consisting of an `IpAddress.V4` and a prefix/netmask
48+
- `IpNetwork.V6` representing an IPv6 network consisting of an `IpAddress.V6` and a prefix/netmask
49+
- `IpInterface` — a concrete IP address belonging to a network. Like a network, this is a combination of IP address and prefix/netmask, but with distinctly different semantics:
50+
- `IpInterface.V4` consisting of an `IpAddress.V4` and a prefix/netmask
51+
- `IpInterface.V6` consisting of an `IpAddress.V6` and a prefix/netmask
52+
53+
`IpNetwork`, `IpAddress`, and their IPv4/IPv6 specializations share the `IpAddressAndPrefix` interface hierarchy, which groups common semantics and functionality.
54+
Addresses and networks are not comparable, so this is mainly an application of DRY.
55+
5956

6057
## Using in your Projects
6158

62-
This library is available at maven central.
59+
This library is available at Maven Central.
6360

6461
### Gradle
6562

@@ -78,7 +75,8 @@ val ip6 = IpAddress("2002:ac1d:2d64::1") //returns an IpAddress.V6
7875
val ip4mappedIp6 = IpAddress("0000:0000:0000:0000:0000:FFFF:192.168.255.255") // returns an IPv4-mapped IpAddress.V6
7976
```
8077

81-
Simply `toString()` any IP address to get its string representation, or access `octets` to get its network-oder byte representation.
78+
79+
Simply `toString()` any IP address to get its string representation, or access `octets` to get its network-order byte representation.
8280
An `IpAddress`'s companion object also provides helpful properties such as segment separator, number of octets, and readily usable `Regex` instances to check whether a string is a valid representation of
8381
an IP address or a single address segment.
8482

@@ -102,12 +100,12 @@ Except for JavaScript and Wasm targets (which lack a native non-string IP addres
102100

103101

104102
#### IPv4 Specifics
105-
Though it has long since been superseded by CIDR, `IpAddress.V4` still features a `class` property (albeit marked as deprecated), that indicates its pre-CIDR
103+
Though it has long since been superseded by CIDR, `IpAddress.V4` still features a `class` property (albeit marked as deprecated) that indicates its pre-CIDR
106104
address class.
107105

108106
#### IPv6 Specifics
109107
IPv6 addresses can embed IPv4 addresses in two ways:
110-
* IPv4 _mapped_ addresses: `0000:0000:0000:0000:0000:FFFF:<IPv4 Address in IPv4 Notation>`
108+
* IPv4 _mapped_ addresses: `0000:0000:0000:0000:0000:FFFF:<IPv4 Address in IPv4 Notation>`
111109
* IPv4 _compatible_ addresses: `0000:0000:0000:0000:0000:0000:<IPv4 Address in IPv4 Notation>`
112110

113111
While the former is still very much a thing (and exposed through the `isIpv4Mapped` flag), the latter has been deprecated.
@@ -120,31 +118,27 @@ It is possible to extract the contained IPv4 address from an IPv4-mapped or IPv4
120118

121119
CIDRE models two closely related concepts:
122120
- `IpNetwork`: a contiguous address range, defined by a network address and prefix.
123-
The network’s address itself is part of the network (and for IPv4, the broadcast address is also considered inside for membership checks).
124-
- `IpInterface`: a single address bound to a prefix and associated with a network, and therefore carry a reference to their associated `IpNetwork`.
121+
The network’s address itself is part of the network (and for IPv4, the broadcast address is also considered inside for membership checks).
122+
- `IpInterface`: a single address bound to a prefix and associated with a network, and therefore carries a reference to the associated `IpNetwork`.
125123

126124
Both share the `IpAddressAndPrefix` interface and its respective IPv4 and IPv6 specializations and therefore expose:
127125
- `address` and prefix (CIDR prefix length)
128126
- `netmask` (network-order ByteArray)
129127
- common flags (e.g., `isLinkLocal`, `isLoopback`, `isMulticast`). IPv4- and IPv6-specific flags are available on their
130-
respective interfaces (IpAddressAndPrefix.V4 / V6).
131-
- consistent `toString()` behavior with address/prefix; IPv4 variants also support netmask printing helpers.
128+
respective interfaces (IpAddressAndPrefix.V4 / V6).
129+
- consistent `toString()` behavior ("address/prefix"); IPv4 variants also support netmask printing helpers.
132130

133131

134132
#### Creating IpInterfaces from Networks
135133

136134
Given an `IpAddress` and a prefix, it is possible to get the corresponding network in two ways:
137-
- `IpNetwork(address strict = false)` to create a new `IpNetwork` and deep-copy the ip address into the network's `address` property.
138-
- If `strict = true` the passed address must already be the network address (i.e., correctly masked), according to the specified prefix
139-
- If `strict = false` the passed address will be masked to the network address, according to the specified prefix
140-
- `IpNetwork.forAddress(address, prefix)` creates a new network, referencing and masking the passed `address`. This avoids copying, but modifies any not-correctly-masked address in-place, according to the given `prefix`.
135+
- `IpNetwork(address, strict = false)` to create a new `IpNetwork` and deep-copy the IP address into the network's `address` property.
136+
- If `strict = true`, the passed address must already be the network address (i.e., correctly masked), according to the specified prefix.
137+
- If `strict = false`, the passed address will be masked to the network address according to the specified prefix.
138+
- `IpNetwork.forAddress(address, prefix)` creates a new network, referencing and masking the passed `address`. This avoids copying but modifies any not-correctly-masked address in-place, according to the given `prefix`.
141139

142140
#### Netmasks and Prefixes
143141

144-
CIDRE uses type aliases
145-
- Prefix is a UInt (`typealias Prefix = UInt`)
146-
- Netmask is a network-order byte array (`typealias Netmask = ByteArray`)
147-
148142
Round-tripping between prefixes and netmasks is straightforward:
149143
- Create a netmask from a prefix:
150144
- For a specific IP family: `prefix.toNetmask(IpAddress.Family.V4)` or `prefix.toNetmask(IpAddress.Family.V6)`
@@ -155,9 +149,9 @@ IP addresses can be masked in-place by calling either `mask(prefix)` or `mask(ne
155149
To create a deep-copied masked version of an address, manually `copy()` it before masking.
156150

157151
For IPv4, it is also possible to get a dotted-quad representation and choose a preferred textual form when working with `IpAddressAndPrefix`:
158-
- `netmaskToString()` yields a `#.#.#.#` string
152+
- `netmaskToString()` yields a `#.#.#.#` string.
159153
- `toString(preferNetmaskOverPrefix = true)` prints `A.A.A.A N.N.N.N`, where `A` is an IP address quad and `N` is a netmask quad.
160-
- `toString(preferNetmaskOverPrefix = false)` prints standard `#.#.#.#/prefix`
154+
- `toString(preferNetmaskOverPrefix = false)` prints standard `#.#.#.#/prefix`.
161155

162156
#### Host Ranges and Address Spaces
163157

@@ -166,12 +160,6 @@ Conceptually:
166160
- An `IpInterface` is a single address bound to a prefix.
167161
- The network address is part of the network; for IPv4, the broadcast address (when applicable) is also inside.
168162

169-
Coming soon:
170-
- Iteration over the full address space of a network
171-
- Convenience accessors for first/last interface and broadcast (where applicable)
172-
- Efficient network size computations
173-
174-
175163
#### Containment
176164

177165
Containment checks are explicit (and fast!):
@@ -186,13 +174,13 @@ The `at.asitplus.cidre.byteops` package provides low-level helper functions:
186174

187175
* `infix fun ByteArray.and(other: ByteArray): ByteArray` performing a logical `AND` operation, returning a fresh ByteArray.
188176
* `fun ByteArray.andInplace(other: ByteArray): Int` performing an in-place logical `AND` operation, modifying the receiver ByteArray. Returns the number of modified bits.
189-
* `fun ByteArray.compareUnsignedBE(other: ByteArray): Int` comparing two same-sized byte arrays by interpreting their contents as unsigned BE integers
190-
* `fun Prefix.toNetmask(family: IpAddress.Family): Netmask` converting an `UInt` CIDR prefix to its byte representation
191-
* `fun Netmask.toPrefix(): Prefix` converting a netmask into its CIDR prefix length
177+
* `fun ByteArray.compareUnsignedBE(other: ByteArray): Int` comparing two same-sized byte arrays by interpreting their contents as unsigned BE integers.
178+
* `fun Prefix.toNetmask(family: IpAddress.Family): Netmask` converting a `UInt` CIDR prefix to its byte representation.
179+
* `fun Netmask.toPrefix(): Prefix` converting a netmask into its CIDR prefix length.
192180
* `ByteArray.toShortArray(bigEndian: Boolean = true): ShortArray` grouping pairs of bytes into a short. Useful to get IPv6 hextets from octets.
193181

194182

195-
## Roadmap:
183+
## Roadmap
196184
- More comprehensive tests
197185
- Address range enumeration
198186
- Subnet enumeration (absolute and relative, e.g., `/24` or “+2 bits”)
@@ -209,6 +197,6 @@ Just be sure to observe the contribution guidelines (see [CONTRIBUTING.md](CONTR
209197
---
210198

211199
<p align="center">
212-
The Apache License does not apply to the logos, (including the A-SIT logo) and the project/module name(s), as these are the sole property of
200+
The Apache License does not apply to the logos (including the A-SIT logo) and the project/module name(s), as these are the sole property of
213201
A-SIT/A-SIT Plus GmbH and may not be used in derivative works without explicit permission!
214-
</p>
202+
</p>

0 commit comments

Comments
 (0)