arduino-audio-tools
Loading...
Searching...
No Matches
Net.h
Go to the documentation of this file.
1#pragma once
2
3// in zephyr we use the definitions if they are available
4#if defined(__zephyr__)
5# include <zephyr/kernel.h>
6# if IS_ENABLED(CONFIG_NETWORKING)// prevent double declarations
7# include "zephyr/net/net_ip.h"
8# define IS_NET_DEFINED
9# endif
10#endif
11
12#if !defined(htons) && !defined(IS_NET_DEFINED)
13#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
14# define htonl(x) (((x) << 24 & 0xFF000000UL) | ((x) << 8 & 0x00FF0000UL) | ((x) >> 8 & 0x0000FF00UL) | ((x) >> 24 & 0x000000FFUL))
15# define htons(x) (((uint16_t)(x)&0xff00) >> 8) | (((uint16_t)(x)&0X00FF) << 8)
16# define ntohl(x) htonl(x)
17# define ntohs(x) htons(x)
18#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
19# define htonl(x) x
20# define htons(x) x
21# define ntohl(x) x
22# define ntohs(x) x
23#else
24#error Could not determine byte order
25#endif
26#endif
27
29#ifndef htonll
30#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
31# define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
32# define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
33#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
34# define htonll(x) x
35# define ntohll(x) x
36#endif
37#endif