Last active
January 11, 2024 15:04
-
-
Save alyssais/654f585b6020e5655132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
let isLittleEndian = Int(OSHostByteOrder()) == OSLittleEndian | |
let htons = isLittleEndian ? _OSSwapInt16 : { $0 } | |
let htonl = isLittleEndian ? _OSSwapInt32 : { $0 } | |
let htonll = isLittleEndian ? _OSSwapInt64 : { $0 } | |
let ntohs = isLittleEndian ? _OSSwapInt16 : { $0 } | |
let ntohl = isLittleEndian ? _OSSwapInt32 : { $0 } | |
let ntohll = isLittleEndian ? _OSSwapInt64 : { $0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was super helpful when searching for ntohs equivalent in Swift. Thank you! Robert