Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kit/mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-kit"
version = "0.3.0"
version = "0.3.1"
description = "Facilities composed from openkal's interfaces. Not part of the specification, and structurally incapable of being mistaken for it."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down Expand Up @@ -98,4 +98,4 @@ openkal = "0.25.0"
# same reason: a change spanning the specification and an implementation must be
# tested against both halves as written, not against whichever half is published.
[target.'cfg(os = "linux")'.dev-dependencies]
openkal-linux = { version = "0.25.0", features = ["standalone"] }
openkal-linux = { version = "0.26.0", features = ["standalone"] }
9 changes: 6 additions & 3 deletions kit/src/endpoint.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ constexpr format_result format_v4(const kal_endpoint& ep, char* out, kal_uintptr
if (cap < 22) return { 0, false };

kal_uintptr n = 0;
// EVERY DIGIT OF THE NUMBER (0.3.1). An octet has at most three and a port
// five; written as three, port 8080 came out as "080".
auto digits = [&](unsigned v) {
if (v >= 100) out[n++] = static_cast<char>('0' + (v / 100) % 10);
if (v >= 10) out[n++] = static_cast<char>('0' + (v / 10) % 10);
out[n++] = static_cast<char>('0' + v % 10);
char reversed[5] = {};
int k = 0;
do { reversed[k++] = static_cast<char>('0' + v % 10); v /= 10; } while (v != 0 && k < 5);
while (k > 0) out[n++] = reversed[--k];
};

for (int octet = 0; octet < 4; ++octet) {
Expand Down
21 changes: 21 additions & 0 deletions kit/tests/kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ void endpoint_section() {
std::memcmp(again.ep.addr, ep.addr, 4) == 0,
"formatting and parsing are inverses");
}
// EVERY DIGIT OF A PORT (0.3.1). The formatter wrote at most three digits
// of each number, which is every digit of an octet and not of a port:
// 8080 came out as "080". No port is written as none, and each other one
// is written whole and reads back as itself.
{
struct { kal_u32 port; const char* text; } const ports[] = {
{ 0, "127.0.0.1" },
{ 80, "127.0.0.1:80" },
{ 8080, "127.0.0.1:8080" },
{ 65535, "127.0.0.1:65535" },
};
for (const auto& p : ports) {
char buf[32] = {};
const auto f = format_v4(loopback_v4(p.port), buf, sizeof buf);
const kal_uintptr len = std::strlen(p.text);
check(f.ok && f.n == len && std::memcmp(buf, p.text, len) == 0,
"a port is written with all its digits");
const auto again = parse_v4(buf, f.n);
check(again.ok && again.ep.port == p.port, "and reads back as the port it was");
}
}
{
char small[8] = {};
const auto f = format_v4(loopback_v4(443), small, sizeof small);
Expand Down
Loading