00001
00002
00003
00004 #ifndef __BYTEORDER_H
00005 #define __BYTEORDER_H
00006
00007
00008 #include <arpa/inet.h>
00009
00010
00011 #define swap16(x) ntohs(x)
00012 #define swap32(x) ntohl(x)
00013
00014 #define swap64(x) ((uint64_t)(((uint64_t)(x) << 56) & 0xff00000000000000ULL | \
00015 ((uint64_t)(x) << 40) & 0x00ff000000000000ULL | \
00016 ((uint64_t)(x) << 24) & 0x0000ff0000000000ULL | \
00017 ((uint64_t)(x) << 8) & 0x000000ff00000000ULL | \
00018 ((x) >> 8) & 0x00000000ff000000ULL | \
00019 ((x) >> 24) & 0x0000000000ff0000ULL | \
00020 ((x) >> 40) & 0x000000000000ff00ULL | \
00021 ((x) >> 56) & 0x00000000000000ffULL))
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #define htobe16(x) htons(x)
00040 #define htobe32(x) htonl(x)
00041 #define be16toh(x) ntohs(x)
00042 #define be32toh(x) ntohl(x)
00043
00044 #define HTOBE16(x) (x) = htobe16(x)
00045 #define HTOBE32(x) (x) = htobe32(x)
00046 #define BE32TOH(x) (x) = be32toh(x)
00047 #define BE16TOH(x) (x) = be16toh(x)
00048
00049
00050 #define htole16(x) (x)
00051 #define htole32(x) (x)
00052 #define htole64(x) (x)
00053 #define le16toh(x) (x)
00054 #define le32toh(x) (x)
00055 #define le64toh(x) (x)
00056
00057 #define HTOLE16(x) (void) (x)
00058 #define HTOLE32(x) (void) (x)
00059 #define HTOLE64(x) (void) (x)
00060 #define LE16TOH(x) (void) (x)
00061 #define LE32TOH(x) (void) (x)
00062 #define LE64TOH(x) (void) (x)
00063
00064
00065 #define htobe64(x) swap64(x)
00066 #define be64toh(x) swap64(x)
00067
00068 #define HTOBE64(x) (x) = htobe64(x)
00069 #define BE64TOH(x) (x) = be64toh(x)
00070
00071
00072 #include "libptp-stdint.h"
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #define be16atoh(x) be16toh(*(uint16_t*)(x))
00083 #define be32atoh(x) be32toh(*(uint32_t*)(x))
00084 #define be64atoh(x) be64toh(*(uint64_t*)(x))
00085 #define le16atoh(x) le16toh(*(uint16_t*)(x))
00086 #define le32atoh(x) le32toh(*(uint32_t*)(x))
00087 #define le64atoh(x) le64toh(*(uint64_t*)(x))
00088
00089 #define htobe16a(a,x) *(uint16_t*)(a) = htobe16(x)
00090 #define htobe32a(a,x) *(uint32_t*)(a) = htobe32(x)
00091 #define htobe64a(a,x) *(uint64_t*)(a) = htobe64(x)
00092 #define htole16a(a,x) *(uint16_t*)(a) = htole16(x)
00093 #define htole32a(a,x) *(uint32_t*)(a) = htole32(x)
00094 #define htole64a(a,x) *(uint64_t*)(a) = htole64(x)
00095
00096 #endif