Created
April 3, 2013 16:52
-
-
Save AndriusA/5303028 to your computer and use it in GitHub Desktop.
ntohll
This file contains hidden or 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
| /* Structure used to swap the bytes in a 64-bit unsigned long long. */ | |
| union byteswap_64_u { | |
| unsigned long long a; | |
| uint32_t b[2]; | |
| }; | |
| /* Function to byteswap big endian 64bit unsigned integers | |
| * back to little endian host order on little endian machines. | |
| * As above, on big endian machines this will be a null macro. | |
| * The macro ntohll() is defined in byteorder64.h, and if needed, | |
| * refers to _ntohll() here. | |
| */ | |
| unsigned long long ntohll(unsigned long long x) | |
| { | |
| union byteswap_64_u u1; | |
| union byteswap_64_u u2; | |
| u1.a = x; | |
| u2.b[1] = ntohl(u1.b[0]); | |
| u2.b[0] = ntohl(u1.b[1]); | |
| return u2.a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment