spiped 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/ext/spiped/extconf.rb +3 -0
  3. data/ext/spiped/spiped-source/BUILDING +46 -0
  4. data/ext/spiped/spiped-source/CHANGELOG +44 -0
  5. data/ext/spiped/spiped-source/COPYRIGHT +33 -0
  6. data/ext/spiped/spiped-source/Makefile +47 -0
  7. data/ext/spiped/spiped-source/Makefile.POSIX +27 -0
  8. data/ext/spiped/spiped-source/Makefile.inc +20 -0
  9. data/ext/spiped/spiped-source/Makefile.prog +23 -0
  10. data/ext/spiped/spiped-source/POSIX/README +10 -0
  11. data/ext/spiped/spiped-source/POSIX/posix-cflags.sh +10 -0
  12. data/ext/spiped/spiped-source/POSIX/posix-clock_realtime.c +3 -0
  13. data/ext/spiped/spiped-source/POSIX/posix-l.c +1 -0
  14. data/ext/spiped/spiped-source/POSIX/posix-l.sh +14 -0
  15. data/ext/spiped/spiped-source/POSIX/posix-msg_nosignal.c +3 -0
  16. data/ext/spiped/spiped-source/README +198 -0
  17. data/ext/spiped/spiped-source/STYLE +151 -0
  18. data/ext/spiped/spiped-source/lib/dnsthread/dnsthread.c +464 -0
  19. data/ext/spiped/spiped-source/lib/dnsthread/dnsthread.h +45 -0
  20. data/ext/spiped/spiped-source/libcperciva/alg/sha256.c +442 -0
  21. data/ext/spiped/spiped-source/libcperciva/alg/sha256.h +95 -0
  22. data/ext/spiped/spiped-source/libcperciva/cpusupport/Build/cpusupport-X86-AESNI.c +13 -0
  23. data/ext/spiped/spiped-source/libcperciva/cpusupport/Build/cpusupport-X86-CPUID.c +8 -0
  24. data/ext/spiped/spiped-source/libcperciva/cpusupport/Build/cpusupport.sh +37 -0
  25. data/ext/spiped/spiped-source/libcperciva/cpusupport/cpusupport.h +63 -0
  26. data/ext/spiped/spiped-source/libcperciva/cpusupport/cpusupport_x86_aesni.c +30 -0
  27. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_aes.c +166 -0
  28. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_aes.h +31 -0
  29. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_aes_aesni.c +229 -0
  30. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_aes_aesni.h +31 -0
  31. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_aesctr.c +124 -0
  32. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_aesctr.h +41 -0
  33. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_dh.c +293 -0
  34. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_dh.h +43 -0
  35. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_dh_group14.c +46 -0
  36. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_dh_group14.h +9 -0
  37. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_entropy.c +215 -0
  38. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_entropy.h +14 -0
  39. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_verify_bytes.c +21 -0
  40. data/ext/spiped/spiped-source/libcperciva/crypto/crypto_verify_bytes.h +14 -0
  41. data/ext/spiped/spiped-source/libcperciva/datastruct/elasticarray.c +276 -0
  42. data/ext/spiped/spiped-source/libcperciva/datastruct/elasticarray.h +167 -0
  43. data/ext/spiped/spiped-source/libcperciva/datastruct/mpool.h +85 -0
  44. data/ext/spiped/spiped-source/libcperciva/datastruct/ptrheap.c +334 -0
  45. data/ext/spiped/spiped-source/libcperciva/datastruct/ptrheap.h +89 -0
  46. data/ext/spiped/spiped-source/libcperciva/datastruct/timerqueue.c +241 -0
  47. data/ext/spiped/spiped-source/libcperciva/datastruct/timerqueue.h +60 -0
  48. data/ext/spiped/spiped-source/libcperciva/events/events.c +203 -0
  49. data/ext/spiped/spiped-source/libcperciva/events/events.h +106 -0
  50. data/ext/spiped/spiped-source/libcperciva/events/events_immediate.c +149 -0
  51. data/ext/spiped/spiped-source/libcperciva/events/events_internal.h +95 -0
  52. data/ext/spiped/spiped-source/libcperciva/events/events_network.c +347 -0
  53. data/ext/spiped/spiped-source/libcperciva/events/events_network_selectstats.c +106 -0
  54. data/ext/spiped/spiped-source/libcperciva/events/events_timer.c +273 -0
  55. data/ext/spiped/spiped-source/libcperciva/network/network.h +95 -0
  56. data/ext/spiped/spiped-source/libcperciva/network/network_accept.c +103 -0
  57. data/ext/spiped/spiped-source/libcperciva/network/network_connect.c +258 -0
  58. data/ext/spiped/spiped-source/libcperciva/network/network_read.c +155 -0
  59. data/ext/spiped/spiped-source/libcperciva/network/network_write.c +188 -0
  60. data/ext/spiped/spiped-source/libcperciva/util/asprintf.c +49 -0
  61. data/ext/spiped/spiped-source/libcperciva/util/asprintf.h +16 -0
  62. data/ext/spiped/spiped-source/libcperciva/util/daemonize.c +134 -0
  63. data/ext/spiped/spiped-source/libcperciva/util/daemonize.h +10 -0
  64. data/ext/spiped/spiped-source/libcperciva/util/entropy.c +76 -0
  65. data/ext/spiped/spiped-source/libcperciva/util/entropy.h +13 -0
  66. data/ext/spiped/spiped-source/libcperciva/util/imalloc.h +33 -0
  67. data/ext/spiped/spiped-source/libcperciva/util/insecure_memzero.c +19 -0
  68. data/ext/spiped/spiped-source/libcperciva/util/insecure_memzero.h +33 -0
  69. data/ext/spiped/spiped-source/libcperciva/util/monoclock.c +52 -0
  70. data/ext/spiped/spiped-source/libcperciva/util/monoclock.h +14 -0
  71. data/ext/spiped/spiped-source/libcperciva/util/noeintr.c +54 -0
  72. data/ext/spiped/spiped-source/libcperciva/util/noeintr.h +14 -0
  73. data/ext/spiped/spiped-source/libcperciva/util/sock.c +472 -0
  74. data/ext/spiped/spiped-source/libcperciva/util/sock.h +56 -0
  75. data/ext/spiped/spiped-source/libcperciva/util/sock_internal.h +14 -0
  76. data/ext/spiped/spiped-source/libcperciva/util/sock_util.c +271 -0
  77. data/ext/spiped/spiped-source/libcperciva/util/sock_util.h +51 -0
  78. data/ext/spiped/spiped-source/libcperciva/util/sysendian.h +146 -0
  79. data/ext/spiped/spiped-source/libcperciva/util/warnp.c +76 -0
  80. data/ext/spiped/spiped-source/libcperciva/util/warnp.h +59 -0
  81. data/ext/spiped/spiped-source/proto/proto_conn.c +362 -0
  82. data/ext/spiped/spiped-source/proto/proto_conn.h +25 -0
  83. data/ext/spiped/spiped-source/proto/proto_crypt.c +396 -0
  84. data/ext/spiped/spiped-source/proto/proto_crypt.h +102 -0
  85. data/ext/spiped/spiped-source/proto/proto_handshake.c +330 -0
  86. data/ext/spiped/spiped-source/proto/proto_handshake.h +30 -0
  87. data/ext/spiped/spiped-source/proto/proto_pipe.c +202 -0
  88. data/ext/spiped/spiped-source/proto/proto_pipe.h +23 -0
  89. data/ext/spiped/spiped-source/spipe/Makefile +90 -0
  90. data/ext/spiped/spiped-source/spipe/README +24 -0
  91. data/ext/spiped/spiped-source/spipe/main.c +178 -0
  92. data/ext/spiped/spiped-source/spipe/pushbits.c +101 -0
  93. data/ext/spiped/spiped-source/spipe/pushbits.h +10 -0
  94. data/ext/spiped/spiped-source/spipe/spipe.1 +60 -0
  95. data/ext/spiped/spiped-source/spiped/Makefile +98 -0
  96. data/ext/spiped/spiped-source/spiped/README +62 -0
  97. data/ext/spiped/spiped-source/spiped/dispatch.c +214 -0
  98. data/ext/spiped/spiped-source/spiped/dispatch.h +27 -0
  99. data/ext/spiped/spiped-source/spiped/main.c +267 -0
  100. data/ext/spiped/spiped-source/spiped/spiped.1 +112 -0
  101. data/lib/spiped.rb +3 -0
  102. metadata +143 -0
@@ -0,0 +1,56 @@
1
+ #ifndef _SOCK_H_
2
+ #define _SOCK_H_
3
+
4
+ /**
5
+ * Address strings are of the following forms:
6
+ * /path/to/unix/socket
7
+ * [ip.v4.ad.dr]:port
8
+ * [ipv6:add::ress]:port
9
+ * host.name:port
10
+ */
11
+
12
+ /* Opaque address structure. */
13
+ struct sock_addr;
14
+
15
+ /**
16
+ * sock_resolve(addr):
17
+ * Return a NULL-terminated array of pointers to sock_addr structures.
18
+ */
19
+ struct sock_addr ** sock_resolve(const char *);
20
+
21
+ /**
22
+ * sock_listener(sa):
23
+ * Create a socket, set SO_REUSEADDR, bind it to the socket address ${sa},
24
+ * mark it for listening, and mark it as non-blocking.
25
+ */
26
+ int sock_listener(const struct sock_addr *);
27
+
28
+ /**
29
+ * sock_connect(sas):
30
+ * Iterate through the addresses in ${sas}, attempting to create a socket and
31
+ * connect (blockingly). Once connected, stop iterating, mark the socket as
32
+ * non-blocking, and return it.
33
+ */
34
+ int sock_connect(struct sock_addr * const *);
35
+
36
+ /**
37
+ * sock_connect_nb(sa):
38
+ * Create a socket, mark it as non-blocking, and attempt to connect to the
39
+ * address ${sa}. Return the socket (connected or in the process of
40
+ * connecting) or -1 on error.
41
+ */
42
+ int sock_connect_nb(const struct sock_addr *);
43
+
44
+ /**
45
+ * sock_addr_free(sa):
46
+ * Free the provided sock_addr structure.
47
+ */
48
+ void sock_addr_free(struct sock_addr *);
49
+
50
+ /**
51
+ * sock_addr_freelist(sas):
52
+ * Free the provided NULL-terminated array of sock_addr structures.
53
+ */
54
+ void sock_addr_freelist(struct sock_addr **);
55
+
56
+ #endif /* !_SOCK_H_ */
@@ -0,0 +1,14 @@
1
+ #ifndef _SOCK_INTERNAL_H_
2
+ #define _SOCK_INTERNAL_H_
3
+
4
+ #include <sys/socket.h>
5
+
6
+ /* Socket address structure. */
7
+ struct sock_addr {
8
+ int ai_family;
9
+ int ai_socktype;
10
+ struct sockaddr * name;
11
+ socklen_t namelen;
12
+ };
13
+
14
+ #endif /* !_SOCK_INTERNAL_H_ */
@@ -0,0 +1,271 @@
1
+ #include <sys/socket.h>
2
+ #include <sys/un.h>
3
+
4
+ #include <netinet/in.h>
5
+
6
+ #include <arpa/inet.h>
7
+
8
+ #include <stdlib.h>
9
+ #include <string.h>
10
+
11
+ #include "asprintf.h"
12
+ #include "sock.h"
13
+
14
+ #include "sock_util.h"
15
+ #include "sock_internal.h"
16
+
17
+ /**
18
+ * sock_addr_cmp(sa1, sa2):
19
+ * Return non-zero iff the socket addresses ${sa1} and ${sa2} are different.
20
+ */
21
+ int
22
+ sock_addr_cmp(const struct sock_addr * sa1, const struct sock_addr * sa2)
23
+ {
24
+
25
+ /* Family, socket type, and name length must match. */
26
+ if ((sa1->ai_family != sa2->ai_family) ||
27
+ (sa1->ai_socktype != sa2->ai_socktype) ||
28
+ (sa1->namelen != sa2->namelen))
29
+ return (1);
30
+
31
+ /* The required length of the sockaddr must match. */
32
+ if (memcmp(sa1->name, sa2->name, sa1->namelen) != 0)
33
+ return (1);
34
+
35
+ /* Everything matched. */
36
+ return (0);
37
+ }
38
+
39
+ /**
40
+ * sock_addr_dup(sa):
41
+ * Duplicate the provided socket address.
42
+ */
43
+ struct sock_addr *
44
+ sock_addr_dup(const struct sock_addr * sa)
45
+ {
46
+ struct sock_addr * sa2;
47
+
48
+ /* Allocate a struct sock_addr and copy fields. */
49
+ if ((sa2 = malloc(sizeof(struct sock_addr))) == NULL)
50
+ goto err0;
51
+ sa2->ai_family = sa->ai_family;
52
+ sa2->ai_socktype = sa->ai_socktype;
53
+ sa2->namelen = sa->namelen;
54
+
55
+ /* Allocate and copy the sockaddr. */
56
+ if ((sa2->name = malloc(sa2->namelen)) == NULL)
57
+ goto err1;
58
+ memcpy(sa2->name, sa->name, sa2->namelen);
59
+
60
+ /* Success! */
61
+ return (sa2);
62
+
63
+ err1:
64
+ free(sa2);
65
+ err0:
66
+ /* Failure! */
67
+ return (NULL);
68
+ }
69
+
70
+ /**
71
+ * sock_addr_duplist(sas):
72
+ * Duplicate the provided list of socket addresses.
73
+ */
74
+ struct sock_addr **
75
+ sock_addr_duplist(struct sock_addr * const * sas)
76
+ {
77
+ struct sock_addr ** sas2;
78
+ size_t i;
79
+
80
+ /* Count socket addresses. */
81
+ for (i = 0; sas[i] != NULL; i++)
82
+ continue;
83
+
84
+ /* Allocate the list to hold addresses plus a NULL terminator. */
85
+ if ((sas2 = malloc((i + 1) * sizeof(struct sock_addr *))) == NULL)
86
+ goto err0;
87
+
88
+ /* Duplicate addresses and NULL-terminate. */
89
+ for (i = 0; sas[i] != NULL; i++) {
90
+ if ((sas2[i] = sock_addr_dup(sas[i])) == NULL)
91
+ goto err1;
92
+ }
93
+ sas2[i] = NULL;
94
+
95
+ /* Success! */
96
+ return (sas2);
97
+
98
+ err1:
99
+ /*
100
+ * Regardless of how many addresses we managed to duplicate before
101
+ * failing and being sent here, we have a valid socket address list,
102
+ * since the erroring sock_addr_dup call NULL-terminated it for us;
103
+ * so we can free it and its constituent addresses easily.
104
+ */
105
+ sock_addr_freelist(sas2);
106
+ err0:
107
+ /* Failure! */
108
+ return (NULL);
109
+ }
110
+
111
+ /**
112
+ * sock_addr_serialize(sa, buf, buflen):
113
+ * Allocate a buffer and serialize the socket address ${sa} into it. Return
114
+ * the buffer via ${buf} and its length via ${buflen}. The serialization is
115
+ * machine and operating system dependent.
116
+ */
117
+ int
118
+ sock_addr_serialize(const struct sock_addr * sa,
119
+ uint8_t ** buf, size_t * buflen)
120
+ {
121
+ uint8_t * p;
122
+
123
+ /* Compute buffer length and allocate buffer. */
124
+ *buflen = 2 * sizeof(int) + sizeof(socklen_t) + sa->namelen;
125
+ if ((p = *buf = malloc(*buflen)) == NULL)
126
+ goto err0;
127
+
128
+ /* Copy in data. */
129
+ memcpy(p, &sa->ai_family, sizeof(int));
130
+ p += sizeof(int);
131
+ memcpy(p, &sa->ai_socktype, sizeof(int));
132
+ p += sizeof(int);
133
+ memcpy(p, &sa->namelen, sizeof(socklen_t));
134
+ p += sizeof(socklen_t);
135
+ memcpy(p, sa->name, sa->namelen);
136
+
137
+ /* Success! */
138
+ return (0);
139
+
140
+ err0:
141
+ /* Failure! */
142
+ return (-1);
143
+ }
144
+
145
+ /**
146
+ * sock_addr_deserialize(buf, buflen):
147
+ * Deserialize the ${buflen}-byte serialized socket address from ${buf}.
148
+ */
149
+ struct sock_addr *
150
+ sock_addr_deserialize(const uint8_t * buf, size_t buflen)
151
+ {
152
+ struct sock_addr * sa;
153
+
154
+ /* Sanity check. */
155
+ if (buflen < 2 * sizeof(int) + sizeof(socklen_t))
156
+ goto err0;
157
+
158
+ /* Allocate a structure and copy in fields. */
159
+ if ((sa = malloc(sizeof(struct sock_addr))) == NULL)
160
+ goto err0;
161
+ memcpy(&sa->ai_family, buf, sizeof(int));
162
+ buf += sizeof(int);
163
+ memcpy(&sa->ai_socktype, buf, sizeof(int));
164
+ buf += sizeof(int);
165
+ memcpy(&sa->namelen, buf, sizeof(socklen_t));
166
+ buf += sizeof(socklen_t);
167
+
168
+ /* Allocate and copy the sockaddr. */
169
+ if (buflen != 2 * sizeof(int) + sizeof(socklen_t) + sa->namelen)
170
+ goto err1;
171
+ if ((sa->name = malloc(sa->namelen)) == NULL)
172
+ goto err1;
173
+ memcpy(sa->name, buf, sa->namelen);
174
+
175
+ /* Success! */
176
+ return (sa);
177
+
178
+ err1:
179
+ free(sa);
180
+ err0:
181
+ /* Failure! */
182
+ return (NULL);
183
+ }
184
+
185
+ /* Prettyprint an IPv4 address. */
186
+ static char *
187
+ prettyprint_ipv4(struct sockaddr * name, size_t namelen)
188
+ {
189
+ struct sockaddr_in sa_in;
190
+ char addr[INET_ADDRSTRLEN];
191
+ char * s;
192
+
193
+ /* Check name length. */
194
+ if (namelen != sizeof(struct sockaddr_in))
195
+ return (NULL);
196
+
197
+ /* Copy into buffer for alignment. */
198
+ memcpy(&sa_in, name, namelen);
199
+
200
+ /* Convert IP address to string. */
201
+ if (inet_ntop(AF_INET, &sa_in.sin_addr, addr, sizeof(addr)) == NULL)
202
+ return (NULL);
203
+
204
+ /* Construct address string. */
205
+ if (asprintf(&s, "[%s]:%d", addr, ntohs(sa_in.sin_port)) == -1)
206
+ return (NULL);
207
+
208
+ /* Success! */
209
+ return (s);
210
+ }
211
+
212
+ /* Prettyprint an IPv6 address. */
213
+ static char *
214
+ prettyprint_ipv6(struct sockaddr * name, size_t namelen)
215
+ {
216
+ struct sockaddr_in6 sa_in6;
217
+ char addr[INET6_ADDRSTRLEN];
218
+ char * s;
219
+
220
+ /* Check name length. */
221
+ if (namelen != sizeof(struct sockaddr_in6))
222
+ return (NULL);
223
+
224
+ /* Copy into buffer for alignment. */
225
+ memcpy(&sa_in6, name, namelen);
226
+
227
+ /* Convert IPv6 address to string. */
228
+ if (inet_ntop(AF_INET6, &sa_in6.sin6_addr, addr, sizeof(addr)) == NULL)
229
+ return (NULL);
230
+
231
+ /* Construct address string. */
232
+ if (asprintf(&s, "[%s]:%d", addr, ntohs(sa_in6.sin6_port)) == -1)
233
+ return (NULL);
234
+
235
+ /* Success! */
236
+ return (s);
237
+ }
238
+
239
+ /* Prettyprint a UNIX address. */
240
+ static char *
241
+ prettyprint_unix(struct sockaddr_un * name)
242
+ {
243
+
244
+ /* Just strdup the path. */
245
+ return (strdup(name->sun_path));
246
+ }
247
+
248
+ /**
249
+ * sock_addr_prettyprint(sa):
250
+ * Allocate and return a string in one of the forms
251
+ * /path/to/unix/socket
252
+ * [ip.v4.ad.dr]:port
253
+ * [ipv6:add::ress]:port
254
+ * representing the provided socket address.
255
+ */
256
+ char *
257
+ sock_addr_prettyprint(const struct sock_addr * sa)
258
+ {
259
+
260
+ /* Handle different types of addresses differently. */
261
+ switch (sa->ai_family) {
262
+ case AF_INET:
263
+ return (prettyprint_ipv4(sa->name, sa->namelen));
264
+ case AF_INET6:
265
+ return (prettyprint_ipv6(sa->name, sa->namelen));
266
+ case AF_UNIX:
267
+ return (prettyprint_unix((struct sockaddr_un *)(sa->name)));
268
+ default:
269
+ return (strdup("Unknown address"));
270
+ }
271
+ }
@@ -0,0 +1,51 @@
1
+ #ifndef _SOCK_UTIL_H_
2
+ #define _SOCK_UTIL_H_
3
+
4
+ #include <stdint.h>
5
+
6
+ /* Opaque address structure. */
7
+ struct sock_addr;
8
+
9
+ /**
10
+ * sock_addr_cmp(sa1, sa2):
11
+ * Return non-zero iff the socket addresses ${sa1} and ${sa2} are different.
12
+ */
13
+ int sock_addr_cmp(const struct sock_addr *, const struct sock_addr *);
14
+
15
+ /**
16
+ * sock_addr_dup(sa):
17
+ * Duplicate the provided socket address.
18
+ */
19
+ struct sock_addr * sock_addr_dup(const struct sock_addr *);
20
+
21
+ /**
22
+ * sock_addr_duplist(sas):
23
+ * Duplicate the provided list of socket addresses.
24
+ */
25
+ struct sock_addr ** sock_addr_duplist(struct sock_addr * const *);
26
+
27
+ /**
28
+ * sock_addr_serialize(sa, buf, buflen):
29
+ * Allocate a buffer and serialize the socket address ${sa} into it. Return
30
+ * the buffer via ${buf} and its length via ${buflen}. The serialization is
31
+ * machine and operating system dependent.
32
+ */
33
+ int sock_addr_serialize(const struct sock_addr *, uint8_t **, size_t *);
34
+
35
+ /**
36
+ * sock_addr_deserialize(buf, buflen):
37
+ * Deserialize the ${buflen}-byte serialized socket address from ${buf}.
38
+ */
39
+ struct sock_addr * sock_addr_deserialize(const uint8_t *, size_t);
40
+
41
+ /**
42
+ * sock_addr_prettyprint(sa):
43
+ * Allocate and return a string in one of the forms
44
+ * /path/to/unix/socket
45
+ * [ip.v4.ad.dr]:port
46
+ * [ipv6:add::ress]:port
47
+ * representing the provided socket address.
48
+ */
49
+ char * sock_addr_prettyprint(const struct sock_addr *);
50
+
51
+ #endif /* !_SOCK_H_ */
@@ -0,0 +1,146 @@
1
+ #ifndef _SYSENDIAN_H_
2
+ #define _SYSENDIAN_H_
3
+
4
+ #include <stdint.h>
5
+
6
+ /* Avoid namespace collisions with BSD <sys/endian.h>. */
7
+ #define be16dec libcperciva_be16dec
8
+ #define be16enc libcperciva_be16enc
9
+ #define be32dec libcperciva_be32dec
10
+ #define be32enc libcperciva_be32enc
11
+ #define be64dec libcperciva_be64dec
12
+ #define be64enc libcperciva_be64enc
13
+ #define le16dec libcperciva_le16dec
14
+ #define le16enc libcperciva_le16enc
15
+ #define le32dec libcperciva_le32dec
16
+ #define le32enc libcperciva_le32enc
17
+ #define le64dec libcperciva_le64dec
18
+ #define le64enc libcperciva_le64enc
19
+
20
+ static inline uint16_t
21
+ be16dec(const void * pp)
22
+ {
23
+ const uint8_t * p = (uint8_t const *)pp;
24
+
25
+ return ((uint16_t)(p[1]) + ((uint16_t)(p[0]) << 8));
26
+ }
27
+
28
+ static inline void
29
+ be16enc(void * pp, uint16_t x)
30
+ {
31
+ uint8_t * p = (uint8_t *)pp;
32
+
33
+ p[1] = x & 0xff;
34
+ p[0] = (x >> 8) & 0xff;
35
+ }
36
+
37
+ static inline uint32_t
38
+ be32dec(const void * pp)
39
+ {
40
+ const uint8_t * p = (uint8_t const *)pp;
41
+
42
+ return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
43
+ ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
44
+ }
45
+
46
+ static inline void
47
+ be32enc(void * pp, uint32_t x)
48
+ {
49
+ uint8_t * p = (uint8_t *)pp;
50
+
51
+ p[3] = x & 0xff;
52
+ p[2] = (x >> 8) & 0xff;
53
+ p[1] = (x >> 16) & 0xff;
54
+ p[0] = (x >> 24) & 0xff;
55
+ }
56
+
57
+ static inline uint64_t
58
+ be64dec(const void * pp)
59
+ {
60
+ const uint8_t * p = (uint8_t const *)pp;
61
+
62
+ return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) +
63
+ ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) +
64
+ ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) +
65
+ ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
66
+ }
67
+
68
+ static inline void
69
+ be64enc(void * pp, uint64_t x)
70
+ {
71
+ uint8_t * p = (uint8_t *)pp;
72
+
73
+ p[7] = x & 0xff;
74
+ p[6] = (x >> 8) & 0xff;
75
+ p[5] = (x >> 16) & 0xff;
76
+ p[4] = (x >> 24) & 0xff;
77
+ p[3] = (x >> 32) & 0xff;
78
+ p[2] = (x >> 40) & 0xff;
79
+ p[1] = (x >> 48) & 0xff;
80
+ p[0] = (x >> 56) & 0xff;
81
+ }
82
+
83
+ static inline uint16_t
84
+ le16dec(const void * pp)
85
+ {
86
+ const uint8_t * p = (uint8_t const *)pp;
87
+
88
+ return ((uint16_t)(p[0]) + ((uint16_t)(p[1]) << 8));
89
+ }
90
+
91
+ static inline void
92
+ le16enc(void * pp, uint16_t x)
93
+ {
94
+ uint8_t * p = (uint8_t *)pp;
95
+
96
+ p[0] = x & 0xff;
97
+ p[1] = (x >> 8) & 0xff;
98
+ }
99
+
100
+ static inline uint32_t
101
+ le32dec(const void * pp)
102
+ {
103
+ const uint8_t * p = (uint8_t const *)pp;
104
+
105
+ return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
106
+ ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
107
+ }
108
+
109
+ static inline void
110
+ le32enc(void * pp, uint32_t x)
111
+ {
112
+ uint8_t * p = (uint8_t *)pp;
113
+
114
+ p[0] = x & 0xff;
115
+ p[1] = (x >> 8) & 0xff;
116
+ p[2] = (x >> 16) & 0xff;
117
+ p[3] = (x >> 24) & 0xff;
118
+ }
119
+
120
+ static inline uint64_t
121
+ le64dec(const void * pp)
122
+ {
123
+ const uint8_t * p = (uint8_t const *)pp;
124
+
125
+ return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) +
126
+ ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) +
127
+ ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) +
128
+ ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
129
+ }
130
+
131
+ static inline void
132
+ le64enc(void * pp, uint64_t x)
133
+ {
134
+ uint8_t * p = (uint8_t *)pp;
135
+
136
+ p[0] = x & 0xff;
137
+ p[1] = (x >> 8) & 0xff;
138
+ p[2] = (x >> 16) & 0xff;
139
+ p[3] = (x >> 24) & 0xff;
140
+ p[4] = (x >> 32) & 0xff;
141
+ p[5] = (x >> 40) & 0xff;
142
+ p[6] = (x >> 48) & 0xff;
143
+ p[7] = (x >> 56) & 0xff;
144
+ }
145
+
146
+ #endif /* !_SYSENDIAN_H_ */