Home | History | Annotate | Download | only in src
      1 /* This file is generated automatically by configure */
      2 /* It is valid only for the system type i386-apple-darwin10.4.0 */
      3 
      4 #ifndef __BYTEORDER_H
      5 #define __BYTEORDER_H
      6 
      7 /* ntohl and relatives live here */
      8 #include <arpa/inet.h>
      9 
     10 /* Define generic byte swapping functions */
     11 #include <machine/byte_order.h>
     12 #define swap16(x) NXSwapShort(x)
     13 #define swap32(x) NXSwapLong(x)
     14 #define swap64(x) NXSwapLongLong(x)
     15 
     16 /* The byte swapping macros have the form: */
     17 /*   EENN[a]toh or htoEENN[a] where EE is be (big endian) or */
     18 /* le (little-endian), NN is 16 or 32 (number of bits) and a, */
     19 /* if present, indicates that the endian side is a pointer to an */
     20 /* array of uint8_t bytes instead of an integer of the specified length. */
     21 /* h refers to the host's ordering method. */
     22 
     23 /* So, to convert a 32-bit integer stored in a buffer in little-endian */
     24 /* format into a uint32_t usable on this machine, you could use: */
     25 /*   uint32_t value = le32atoh(&buf[3]); */
     26 /* To put that value back into the buffer, you could use: */
     27 /*   htole32a(&buf[3], value); */
     28 
     29 /* Define aliases for the standard byte swapping macros */
     30 /* Arguments to these macros must be properly aligned on natural word */
     31 /* boundaries in order to work properly on all architectures */
     32 #ifndef htobe16
     33 # define htobe16(x) htons(x)
     34 #endif
     35 #ifndef htobe32
     36 # define htobe32(x) htonl(x)
     37 #endif
     38 #ifndef be16toh
     39 # define be16toh(x) ntohs(x)
     40 #endif
     41 #ifndef be32toh
     42 # define be32toh(x) ntohl(x)
     43 #endif
     44 
     45 #define HTOBE16(x) (x) = htobe16(x)
     46 #define HTOBE32(x) (x) = htobe32(x)
     47 #define BE32TOH(x) (x) = be32toh(x)
     48 #define BE16TOH(x) (x) = be16toh(x)
     49 
     50 /* On little endian machines, these macros are null */
     51 #ifndef htole16
     52 # define htole16(x)      (x)
     53 #endif
     54 #ifndef htole32
     55 # define htole32(x)      (x)
     56 #endif
     57 #ifndef htole64
     58 # define htole64(x)      (x)
     59 #endif
     60 #ifndef le16toh
     61 # define le16toh(x)      (x)
     62 #endif
     63 #ifndef le32toh
     64 # define le32toh(x)      (x)
     65 #endif
     66 #ifndef le64toh
     67 # define le64toh(x)      (x)
     68 #endif
     69 
     70 #define HTOLE16(x)      (void) (x)
     71 #define HTOLE32(x)      (void) (x)
     72 #define HTOLE64(x)      (void) (x)
     73 #define LE16TOH(x)      (void) (x)
     74 #define LE32TOH(x)      (void) (x)
     75 #define LE64TOH(x)      (void) (x)
     76 
     77 /* These don't have standard aliases */
     78 #ifndef htobe64
     79 # define htobe64(x)      swap64(x)
     80 #endif
     81 #ifndef be64toh
     82 # define be64toh(x)      swap64(x)
     83 #endif
     84 
     85 #define HTOBE64(x)      (x) = htobe64(x)
     86 #define BE64TOH(x)      (x) = be64toh(x)
     87 
     88 /* Define the C99 standard length-specific integer types */
     89 #include <stdint.h>
     90 
     91 /* Here are some macros to create integers from a byte array */
     92 /* These are used to get and put integers from/into a uint8_t array */
     93 /* with a specific endianness.  This is the most portable way to generate */
     94 /* and read messages to a network or serial device.  Each member of a */
     95 /* packet structure must be handled separately. */
     96 
     97 /* The i386 and compatibles can handle unaligned memory access, */
     98 /* so use the optimized macros above to do this job */
     99 #ifndef be16atoh
    100 # define be16atoh(x)     be16toh(*(uint16_t*)(x))
    101 #endif
    102 #ifndef be32atoh
    103 # define be32atoh(x)     be32toh(*(uint32_t*)(x))
    104 #endif
    105 #ifndef be64atoh
    106 # define be64atoh(x)     be64toh(*(uint64_t*)(x))
    107 #endif
    108 #ifndef le16atoh
    109 # define le16atoh(x)     le16toh(*(uint16_t*)(x))
    110 #endif
    111 #ifndef le32atoh
    112 # define le32atoh(x)     le32toh(*(uint32_t*)(x))
    113 #endif
    114 #ifndef le64atoh
    115 # define le64atoh(x)     le64toh(*(uint64_t*)(x))
    116 #endif
    117 
    118 #ifndef htob16a
    119 # define htobe16a(a,x)   *(uint16_t*)(a) = htobe16(x)
    120 #endif
    121 #ifndef htobe32a
    122 # define htobe32a(a,x)   *(uint32_t*)(a) = htobe32(x)
    123 #endif
    124 #ifndef htobe64a
    125 # define htobe64a(a,x)   *(uint64_t*)(a) = htobe64(x)
    126 #endif
    127 #ifndef htole16a
    128 # define htole16a(a,x)   *(uint16_t*)(a) = htole16(x)
    129 #endif
    130 #ifndef htole32a
    131 # define htole32a(a,x)   *(uint32_t*)(a) = htole32(x)
    132 #endif
    133 #ifndef htole64a
    134 # define htole64a(a,x)   *(uint64_t*)(a) = htole64(x)
    135 #endif
    136 
    137 #endif /*__BYTEORDER_H*/
    138