Skip to content

Commit 1feb354

Browse files
author
Askar Safin
committed
Add htonl, htons, ntohl, ntohs
1 parent 2fd2b60 commit 1feb354

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libc-test/semver/unix.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ grantpt
583583
group
584584
hostent
585585
hstrerror
586+
htonl
587+
htons
586588
if_indextoname
587589
if_nametoindex
588590
in6_addr
@@ -651,6 +653,8 @@ munmap
651653
nanosleep
652654
nfds_t
653655
nlink_t
656+
ntohl
657+
ntohs
654658
off_t
655659
open
656660
opendir

src/unix/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,23 @@ extern "C" {
13671367

13681368
}
13691369

1370+
safe_f! {
1371+
// It seems htonl, etc are macros on macOS. So we have to reimplement them. So let's
1372+
// reimplement them for all UNIX platforms
1373+
pub {const} fn htonl(hostlong: u32) -> u32 {
1374+
u32::to_be(hostlong)
1375+
}
1376+
pub {const} fn htons(hostshort: u16) -> u16 {
1377+
u16::to_be(hostshort)
1378+
}
1379+
pub {const} fn ntohl(netlong: u32) -> u32 {
1380+
u32::from_be(netlong)
1381+
}
1382+
pub {const} fn ntohs(netshort: u16) -> u16 {
1383+
u16::from_be(netshort)
1384+
}
1385+
}
1386+
13701387
cfg_if! {
13711388
if #[cfg(not(any(target_os = "emscripten",
13721389
target_os = "android",

0 commit comments

Comments
 (0)