Implemented network byte order conversion

This commit is contained in:
2025-02-08 23:59:19 +01:00
parent 9002116ee4
commit 1ff56e0856
4 changed files with 6 additions and 3 deletions

3
lib/net/htons.q Normal file
View File

@ -0,0 +1,3 @@
htons(num Int) -> Int {
return ((num & 0xFF) << 8) | (num >> 8)
}

View File

@ -3,7 +3,7 @@ import sys
bind(socket Int, port Int) -> Int {
addr := new(sys.sockaddr_in)
addr.sin_family = 2
addr.sin_port = port
addr.sin_port = htons(port)
err := sys.bind(socket, addr, 20)
delete(addr)
return err

View File

@ -3,7 +3,7 @@ import sys
bind(socket Int, port Int) -> Int {
addr := new(sys.sockaddr_in_bsd)
addr.sin_family = 2
addr.sin_port = port
addr.sin_port = htons(port)
err := sys.bind(socket, addr, 16)
delete(addr)
return err