~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH hare 1/2] net::ip: minor code updates

Details
Message ID
<166195583285.21873.1476954692285097476-0@git.sr.ht>
DKIM signature
missing
Download raw message
Patch: +21 -23
From: Pierre Curto <pierre.curto@gmail.com>

Add TODO for https://todo.sr.ht/~sircmpwn/hare/536
Sort impports and use the endian module.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
---
 net/ip/ip.ha | 44 +++++++++++++++++++++-----------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/net/ip/ip.ha b/net/ip/ip.ha
index 79275b84..21ee5c54 100644
--- a/net/ip/ip.ha
+++ b/net/ip/ip.ha
@@ -7,13 +7,14 @@
// (c) 2021 Miccah Castorina <contact@miccah.io>
// (c) 2021 Mykyta Holubakha <hilobakho@gmail.com>
// (c) 2021 Thomas Bracht Laumann Jespersen <t@laumann.xyz>
use io;
use strio;
use fmt;
use bytes;
use rt;
use endian;
use fmt;
use io;
use rt; //TODO remove
use strconv;
use strings;
use strio;

// An IPv4 address.
export type addr4 = [4]u8;
@@ -89,10 +90,10 @@ fn parsev4(st: str) (addr4 | invalid) = {

fn parsev6(st: str) (addr6 | invalid) = {
	let ret: addr6 = [0...];
	let tok = strings::tokenize(st, ":");
	if (st == "::") {
		return ret;
	};
	let tok = strings::tokenize(st, ":");
	let ells = -1;
	if (strings::hasprefix(st, "::")) {
		wanttoken(&tok)?;
@@ -116,17 +117,12 @@ fn parsev6(st: str) (addr6 | invalid) = {
			ells = i;
			continue;
		};
		let val = strconv::stou16b(s, 16);
		if (val is u16) {
			let v = val as u16;
			ret[i] = (v >> 8): u8;
			i += 1;
			ret[i] = v: u8;
			i += 1;
			continue;
		} else {
			let v4 = parsev4(s)?;
			rt::memcpy(&ret[i], &v4, 4);
		match (strconv::stou16b(s, 16)) {
		case let val: u16 =>
			endian::beputu16(ret[i..], val);
			i += 2;
		case =>
			ret[i..i + 4] = parsev4(s)?;
			i += 4;
			break;
		};
@@ -138,13 +134,13 @@ fn parsev6(st: str) (addr6 | invalid) = {
		if (i >= 15) {
			return invalid;
		};
		rt::memcpy(
			&ret[16 - (i - ells)],
			&ret[ells], (i - ells): size);
		rt::memset(&ret[ells], 0, (i - ells): size);
	} else {
		if (i != 16)
			return invalid;
		const n = i - ells;
		ret[16 - n..16] = ret[ells..ells + n];
		// TODO: after https://todo.sr.ht/~sircmpwn/hare/536
		// ret[ells..ells + n] = [0...];
		rt::memset(&ret[ells], 0, n: size);
	} else if (i != 16) {
		return invalid;
	};

	return ret;
@@ -217,6 +213,8 @@ fn fmtv6(s: io::handle, a: addr6) (io::error | size) = {
// Fills a netmask according to the CIDR value
// e.g. 23 -> [0xFF, 0xFF, 0xFD, 0x00]
fn fillmask(mask: []u8, val: u8) void = {
	// TODO: after https://todo.sr.ht/~sircmpwn/hare/536
	// mask = [0xFF...];
	rt::memset(&mask[0], 0xFF, len(mask));
	let i: int = len(mask): int - 1;
	val = len(mask): u8 * 8 - val;
-- 
2.34.4

[PATCH hare 2/2] net::dial: handle IPv6 address with port

Details
Message ID
<166195583285.21873.1476954692285097476-1@git.sr.ht>
In-Reply-To
<166195583285.21873.1476954692285097476-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +33 -15
From: Pierre Curto <pierre.curto@gmail.com>

Fixes: https://todo.sr.ht/~sircmpwn/hare/454

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
---
 net/dial/resolve.ha | 48 +++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/net/dial/resolve.ha b/net/dial/resolve.ha
index 0fa27bf0..c7807ee2 100644
--- a/net/dial/resolve.ha
+++ b/net/dial/resolve.ha
@@ -18,24 +18,42 @@ export fn resolve(
	addr: str,
	service: str,
) (([]ip::addr, u16) | error) = {
	let port = match (strings::index(addr, ':')) {
	case void =>
		yield match (strconv::stou16(service)) {
		case let u: u16 =>
			yield u;
		case =>
			yield 0u16;
		};
	case let i: size =>
		const sub = strings::sub(addr, i + 1, strings::end);
		addr = strings::sub(addr, 0, i);
		yield match (strconv::stou16(sub)) {
		case let u: u16 =>
			yield u;
		case =>
	let port = if (strings::hasprefix(addr, '[')) {
		// [::1]:80
		yield match (strings::index(addr, "]:")) {
		case let i: size =>
			const sub = strings::sub(addr, i + 2, strings::end);
			addr = strings::sub(addr, 1, i);
			yield match (strconv::stou16(sub)) {
			case let u: u16 =>
				yield u;
			case =>
				return invalid_address;
			};
		case void =>
			return invalid_address;
		};
	} else {
		yield match (strings::index(addr, ':')) {
		case void =>
			yield match (strconv::stou16(service)) {
			case let u: u16 =>
				yield u;
			case =>
				yield 0u16;
			};
		case let i: size =>
			const sub = strings::sub(addr, i + 1, strings::end);
			addr = strings::sub(addr, 0, i);
			yield match (strconv::stou16(sub)) {
			case let u: u16 =>
				yield u;
			case =>
				return invalid_address;
			};
		};
	};

	if (service == "unknown" && port == 0) {
		return unknown_service;
	};
-- 
2.34.4

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CMKA7J5XQBQD.209K4WR89TS5A@cirno>
In-Reply-To
<166195583285.21873.1476954692285097476-1@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m37s

[net::ip: minor code updates][0] from [~pierrec][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/35045
[1]: pierre.curto@gmail.com

✓ #835566 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/835566
✓ #835567 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/835567
Details
Message ID
<CN2TGHNRSJNJ.2KUN073KSDZHO@taiga>
In-Reply-To
<166195583285.21873.1476954692285097476-0@git.sr.ht> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   27fd53f7..10cf8c9d  master -> master
Reply to thread Export thread (mbox)