Skip to content

Commit e28f87e

Browse files
author
BiffoBear
committed
Check for endidness before converting in htonl and htons.
1 parent b794019 commit e28f87e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
import gc
2626
import time
27+
from sys import byteorder
2728
from micropython import const
28-
2929
import adafruit_wiznet5k as wiznet5k
3030

3131
# pylint: disable=invalid-name
@@ -90,6 +90,8 @@ def htonl(x: int) -> int:
9090
9191
:return int: 32-bit positive integer in network byte order.
9292
"""
93+
if byteorder == "big":
94+
return x
9395
return int.from_bytes(x.to_bytes(4, "little"), "big")
9496

9597

@@ -101,6 +103,8 @@ def htons(x: int) -> int:
101103
102104
:return int: 16-bit positive integer in network byte order.
103105
"""
106+
if byteorder == "big":
107+
return x
104108
return ((x << 8) & 0xFF00) | ((x >> 8) & 0xFF)
105109

106110

0 commit comments

Comments
 (0)