From 0916806350c88355ac80d856520b4f7f72eed600 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 2 Oct 2021 18:20:24 +0300 Subject: [PATCH] ci: do not use htonll and ntohll on windows, use the portable versions instead. --- vlib/net/conv/c_default.c.v | 9 +++++++ vlib/net/conv/c_windows.c.v | 15 +++++++++++ vlib/net/conv/conv.c.v | 39 ++++++++++++++++++++++++++++ vlib/net/conv/conv_default.c.v | 46 ---------------------------------- vlib/net/conv/conv_windows.c.v | 23 ----------------- 5 files changed, 63 insertions(+), 69 deletions(-) create mode 100644 vlib/net/conv/c_default.c.v create mode 100644 vlib/net/conv/c_windows.c.v delete mode 100644 vlib/net/conv/conv_default.c.v delete mode 100644 vlib/net/conv/conv_windows.c.v diff --git a/vlib/net/conv/c_default.c.v b/vlib/net/conv/c_default.c.v new file mode 100644 index 000000000..76c4be0ca --- /dev/null +++ b/vlib/net/conv/c_default.c.v @@ -0,0 +1,9 @@ +module conv + +#include + +fn C.htonl(host u32) u32 +fn C.htons(host u16) u16 + +fn C.ntohl(net u32) u32 +fn C.ntohs(net u16) u16 diff --git a/vlib/net/conv/c_windows.c.v b/vlib/net/conv/c_windows.c.v new file mode 100644 index 000000000..ae0f93e3a --- /dev/null +++ b/vlib/net/conv/c_windows.c.v @@ -0,0 +1,15 @@ +module conv + +#include + +#flag -lws2_32 + +fn C.htonl(host u32) u32 +fn C.htons(host u16) u16 + +fn C.ntohl(net u32) u32 +fn C.ntohs(net u16) u16 + +//** These are not supplied with mingw/gcc ** +// fn C.htonll(host u64) u64 +// fn C.ntohll(net u64) u64 diff --git a/vlib/net/conv/conv.c.v b/vlib/net/conv/conv.c.v index 067c82e6b..ab66f7417 100644 --- a/vlib/net/conv/conv.c.v +++ b/vlib/net/conv/conv.c.v @@ -19,3 +19,42 @@ pub fn nth32(host u32) u32 { pub fn nth16(host u16) u16 { return C.ntohs(host) } + +//****************************** + +struct Bytes { +mut: + first u32 + last u32 +} + +union LongLong { + Bytes + ll u64 +} + +// host to net 64 (htonll) +pub fn htn64(host u64) u64 { + mut ll := LongLong{ + ll: host + } + + unsafe { + ll.first = htn32(ll.first) + ll.last = htn32(ll.last) + } + return unsafe { ll.ll } +} + +// net to host 64 (ntohll) +pub fn nth64(net u64) u64 { + mut ll := LongLong{ + ll: net + } + + unsafe { + ll.first = nth32(ll.first) + ll.last = nth32(ll.last) + } + return unsafe { ll.ll } +} diff --git a/vlib/net/conv/conv_default.c.v b/vlib/net/conv/conv_default.c.v deleted file mode 100644 index dcacf5b79..000000000 --- a/vlib/net/conv/conv_default.c.v +++ /dev/null @@ -1,46 +0,0 @@ -module conv - -#include - -fn C.htonl(host u32) u32 -fn C.htons(host u16) u16 - -fn C.ntohl(net u32) u32 -fn C.ntohs(net u16) u16 - -struct Bytes { -mut: - first u32 - last u32 -} - -union LongLong { - Bytes - ll u64 -} - -// host to net 64 (htonll) -pub fn htn64(host u64) u64 { - mut ll := LongLong{ - ll: host - } - - unsafe { - ll.first = htn32(ll.first) - ll.last = htn32(ll.last) - } - return unsafe { ll.ll } -} - -// net to host 64 (ntohll) -pub fn nth64(net u64) u64 { - mut ll := LongLong{ - ll: net - } - - unsafe { - ll.first = nth32(ll.first) - ll.last = nth32(ll.last) - } - return unsafe { ll.ll } -} diff --git a/vlib/net/conv/conv_windows.c.v b/vlib/net/conv/conv_windows.c.v deleted file mode 100644 index eb15bae4f..000000000 --- a/vlib/net/conv/conv_windows.c.v +++ /dev/null @@ -1,23 +0,0 @@ -module conv - -#include - -#flag -lws2_32 - -fn C.htonll(host u64) u64 -fn C.htonl(host u32) u32 -fn C.htons(host u16) u16 - -fn C.ntohll(net u64) u64 -fn C.ntohl(net u32) u32 -fn C.ntohs(net u16) u16 - -// host to net 64 (htonll) -pub fn htn64(host u64) u64 { - return C.htonll(host) -} - -// net to host 64 (htonll) -pub fn nth64(host u64) u64 { - return C.ntohll(host) -} -- 2.30.2