AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
net.h
1 
18 #ifndef _AVRIO_NET_H_
19 #define _AVRIO_NET_H_
20 
21 #include <avrio/defs.h>
22 __BEGIN_C_DECLS
23 /* ======================================================================== */
34 /* constants ================================================================ */
35 
36 #if defined(__DOXYGEN__)
37 /*
38  * __DOXYGEN__ defined
39  * Partie documentation ne devant pas être compilée.
40  * =============================================================================
41  */
42 
43 /* internal public functions ================================================ */
44 
51 uint16_t ntohs(uint16_t n);
52 
59 uint16_t htons(uint16_t h);
60 
67 uint32_t ntohl(uint32_t n);
68 
75 uint32_t htonl(uint32_t h);
76 
83 uint64_t ntohll(uint64_t n);
84 
91 uint64_t htonll(uint64_t h);
92 
96 uint8_t * pushs (uint8_t * netdata, uint16_t hostshort);
100 uint8_t * pops (uint8_t * netdata, uint16_t * hostshort);
101 
105 uint8_t * pushl (uint8_t * netdata, uint32_t hostlong);
109 uint8_t * popl (uint8_t * netdata, uint32_t * hostlong);
113 uint8_t * pushll (uint8_t * netdata, uint32_t hostlonglong);
117 uint8_t * popll (uint8_t * netdata, uint32_t * hostlonglong);
118 
123 #else
124 /*
125  * __DOXYGEN__ not defined
126  * Partie ne devant pas être documentée.
127  * =============================================================================
128  */
129 
130 #if !defined(ntohs) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
131 //------------------------------------------------------------------------------
132 #include <avrio/util.h> // vSwapBytes() from avrio/util_swapbytes.S
133 INLINE uint16_t
134 ntohs (uint16_t n) {
135 
136  vSwapBytes ( (uint8_t *) &n, sizeof (n));
137  return n;
138 }
139 # define htons(n) ntohs(n)
140 #elif !defined(ntohs)
141 //------------------------------------------------------------------------------
142 # define ntohs(n) ((uint16_t)(n))
143 # define htons(n) ntohs(n)
144 #endif
145 
146 #if !defined(ntohl) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
147 //------------------------------------------------------------------------------
148 #include <avrio/util.h> // vSwapBytes() from avrio/util_swapbytes.S
149 INLINE uint32_t
150 ntohl (uint32_t n) {
151 
152  vSwapBytes ( (uint8_t *) &n, sizeof (n));
153  return n;
154 }
155 # define htonl(n) ntohl(n)
156 #elif !defined(ntohl)
157 //------------------------------------------------------------------------------
158 # define ntohl(n) ((uint32_t)(n))
159 # define htonl(n) ntohl(n)
160 #endif
161 
162 #if !defined(ntohll) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
163 //------------------------------------------------------------------------------
164 #include <avrio/util.h> // vSwapBytes() from avrio/util_swapbytes.S
165 INLINE uint64_t
166 ntohll (uint64_t n) {
167 
168  vSwapBytes ( (uint8_t *) &n, sizeof (n));
169  return n;
170 }
171 # define htonll(n) ntohll(n)
172 
173 #elif !defined(ntohll)
174 //------------------------------------------------------------------------------
175 # define ntohll(n) ((uint64_t)(n))
176 # define htonll(n) ntohll(n)
177 #endif
178 
179 
180 //------------------------------------------------------------------------------
181 INLINE uint8_t *
182 pushs (uint8_t * netdata, uint16_t hostshort) {
183  *PUINT16(netdata) = htons (hostshort);
184  netdata += sizeof(hostshort);
185  return netdata;
186 }
187 
188 //------------------------------------------------------------------------------
189 INLINE uint8_t *
190 pops (uint8_t * netdata, uint16_t * hostshort) {
191  *hostshort = ntohs (*PUINT16(netdata));
192  netdata += sizeof(hostshort);
193  return netdata;
194 }
195 
196 //------------------------------------------------------------------------------
197 INLINE uint8_t *
198 pushl (uint8_t * netdata, uint32_t hostlong) {
199  *PUINT32(netdata) = htonl (hostlong);
200  netdata += sizeof(hostlong);
201  return netdata;
202 }
203 
204 //------------------------------------------------------------------------------
205 INLINE uint8_t *
206 popl (uint8_t * netdata, uint32_t * hostlong) {
207  *hostlong = ntohl (*PUINT32(netdata));
208  netdata += sizeof(hostlong);
209  return netdata;
210 }
211 
212 //------------------------------------------------------------------------------
213 INLINE uint8_t *
214 pushll (uint8_t * netdata, uint32_t hostlonglong) {
215  *PUINT64(netdata) = htonll (hostlonglong);
216  netdata += sizeof(hostlonglong);
217  return netdata;
218 }
219 
220 //------------------------------------------------------------------------------
221 INLINE uint8_t *
222 popll (uint8_t * netdata, uint32_t * hostlonglong) {
223  *hostlonglong = ntohll (*PUINT32(netdata));
224  netdata += sizeof(hostlonglong);
225  return netdata;
226 }
227 
228 #endif /* __DOXYGEN__ not defined */
229 /* ========================================================================== */
230 __END_C_DECLS
231 #endif /* _AVRIO_NET_H_ */
#define PUINT64(p)
Cast p vers un pointeur de type uint64_t *.
Definition: defs.h:383
uint8_t * pops(uint8_t *netdata, uint16_t *hostshort)
uint8_t * pushll(uint8_t *netdata, uint32_t hostlonglong)
uint8_t * pushl(uint8_t *netdata, uint32_t hostlong)
uint16_t ntohs(uint16_t n)
Convertir entier court de l&#39;ordre des octets du réseau vers l&#39;hôte.
uint8_t * popl(uint8_t *netdata, uint32_t *hostlong)
void vSwapBytes(uint8_t *pucBytes, uint8_t ucSize)
Permute les octets 2 à 2.
#define PUINT16(p)
Cast p vers un pointeur de type uint16_t *.
Definition: defs.h:367
uint64_t htonll(uint64_t h)
Convertir entier long long de l&#39;ordre des octets de l&#39;hôte vers le réseau.
uint16_t htons(uint16_t h)
Convertir entier court de l&#39;ordre des octets de l&#39;hôte vers le réseau.
uint8_t * popll(uint8_t *netdata, uint32_t *hostlonglong)
uint8_t * pushs(uint8_t *netdata, uint16_t hostshort)
uint32_t htonl(uint32_t h)
Convertir entier long de l&#39;ordre des octets de l&#39;hôte vers le réseau.
uint32_t ntohl(uint32_t n)
Convertir entier long de l&#39;ordre des octets du réseau vers l&#39;hôte.
#define PUINT32(p)
Cast p vers un pointeur de type uint32_t *.
Definition: defs.h:375
uint64_t ntohll(uint64_t n)
Convertir entier long long de l&#39;ordre des octets du réseau vers l&#39;hôte.