eBPF for Windows
bpf_endian.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation
2 // SPDX-License-Identifier: MIT
3 #pragma once
4 
5 #include <stdint.h>
6 
7 inline __attribute__((always_inline)) uint16_t
8 bpf_ntohs(uint16_t us)
9 {
10  return us << 8 | us >> 8;
11 }
12 
13 #define bpf_htons(x) bpf_ntohs(x)
14 
15 #ifndef ntohs
16 #define ntohs bpf_ntohs
17 #endif
18 #ifndef htons
19 #define htons bpf_htons
20 #endif
21 
22 inline __attribute__((always_inline)) uint32_t
23 bpf_ntohl(uint32_t x)
24 {
25  return (
26  (((x) >> 24) & 0x000000FFL) | (((x) >> 8) & 0x0000FF00L) | (((x) << 8) & 0x00FF0000L) |
27  (((x) << 24) & 0xFF000000L));
28 }
29 
30 #define bpf_htonl(x) bpf_ntohl(x)
31 
32 #ifndef ntohl
33 #define ntohl bpf_ntohl
34 #endif
35 #ifndef htonl
36 #define htonl bpf_htonl
37 #endif
__attribute__
__attribute__((always_inline)) uint16_t bpf_ntohs(uint16_t us)
Definition: bpf_endian.h:7