hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 0dbef0b3412b1e53870f438b3d2d93c36c061ec7
parent e07ee31ce0c0a235e81757ba7c3cdeea2f4957c3
Author: Mykyta Holubakha <hilobakho@gmail.com>
Date:   Mon, 29 Mar 2021 21:26:41 +0300

net/ip: added from_native function

Diffstat:
Mnet/ip/+linux.ha | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/net/ip/+linux.ha b/net/ip/+linux.ha @@ -15,3 +15,22 @@ export fn to_native(a: addr, port: u16) rt::sockaddr = { } }, }; }; + +export fn from_native(a: rt::sockaddr) (addr, u16) = { + let family = a.in.sin_family; + switch (family) { + rt::AF_INET => { + let addr = a.in.sin_addr.s_addr; + return ( + [addr: u8, (addr >> 8): u8, (addr >> 16): u8, + (addr >> 24): u8]: addr4, + endian::ntohu16(a.in.sin_port) + ); + }, + rt::AF_INET6 => return ( + a.in6.sin6_addr.s6_addr: addr6, + endian::ntohu16(a.in6.sin6_port) + ), + * => abort("Wrong address family!"), + }; +};