cutils_endian.h
| 1 | #ifndef CUTILS_ENDIAN_H |
| 2 | #define CUTILS_ENDIAN_H |
| 3 | #include <stdint.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | inline uint32_t ntoh32(uint32_t const net) |
| 7 | { |
| 8 | uint8_t data[4]; |
| 9 | memcpy(&data, &net, sizeof(data)); |
| 10 | |
| 11 | return ((uint32_t) data[3] << 0) |
| 12 | | ((uint32_t) data[2] << 8) |
| 13 | | ((uint32_t) data[1] << 16) |
| 14 | | ((uint32_t) data[0] << 24); |
| 15 | } |
| 16 | |
| 17 | #endif //CUTILS_ENDIAN_H |
| 18 |