]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Network library header. | |
3 | * Copyright (C) 1998 Kunihiro Ishiguro | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #ifndef _ZEBRA_NETWORK_H | |
23 | #define _ZEBRA_NETWORK_H | |
24 | ||
f62de63c DL |
25 | #ifdef HAVE_SYS_ENDIAN_H |
26 | #include <sys/endian.h> | |
27 | #endif | |
28 | #ifdef HAVE_ENDIAN_H | |
29 | #include <endian.h> | |
30 | #endif | |
31 | ||
5e244469 RW |
32 | #ifdef __cplusplus |
33 | extern "C" { | |
34 | #endif | |
35 | ||
a269d613 | 36 | /* Both readn and writen are deprecated and will be removed. They are not |
37 | suitable for use with non-blocking file descriptors. | |
38 | */ | |
d7c0a89a QY |
39 | extern int readn(int, uint8_t *, int); |
40 | extern int writen(int, const uint8_t *, int); | |
718e3744 | 41 | |
a269d613 | 42 | /* Set the file descriptor to use non-blocking I/O. Returns 0 for success, |
43 | -1 on error. */ | |
44 | extern int set_nonblocking(int fd); | |
45 | ||
2da59394 DL |
46 | extern int set_cloexec(int fd); |
47 | ||
d7e2a818 | 48 | /* Does the I/O error indicate that the operation should be retried later? */ |
d62a17ae | 49 | #define ERRNO_IO_RETRY(EN) \ |
d7e2a818 | 50 | (((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR)) |
51 | ||
d62a17ae | 52 | extern float htonf(float); |
53 | extern float ntohf(float); | |
16f1b9ee | 54 | |
f62de63c DL |
55 | /* force type for be64toh/htobe64 to be uint64_t, *without* a direct cast |
56 | * | |
57 | * this is a workaround for false-positive printfrr warnings from FRR's | |
58 | * frr-format GCC plugin that would be triggered from | |
59 | * { printfrr("%"PRIu64, (uint64_t)be64toh(...)); } | |
60 | * | |
61 | * the key element here is that "(uint64_t)expr" causes the warning, while | |
62 | * "({ uint64_t x = expr; x; })" does not. (The cast is the trigger, a | |
63 | * variable of the same type works correctly.) | |
64 | */ | |
65 | ||
66 | /* zap system definitions... */ | |
67 | #ifdef be64toh | |
68 | #undef be64toh | |
69 | #endif | |
70 | #ifdef htobe64 | |
71 | #undef htobe64 | |
72 | #endif | |
73 | ||
74 | #if BYTE_ORDER == LITTLE_ENDIAN | |
75 | #define be64toh(x) ({ uint64_t r = __builtin_bswap64(x); r; }) | |
76 | #define htobe64(x) ({ uint64_t r = __builtin_bswap64(x); r; }) | |
77 | #elif BYTE_ORDER == BIG_ENDIAN | |
78 | #define be64toh(x) ({ uint64_t r = (x); r; }) | |
79 | #define htobe64(x) ({ uint64_t r = (x); r; }) | |
80 | #else | |
81 | #error nobody expects the endianish inquisition. check OS endian.h headers. | |
82 | #endif | |
83 | ||
3c191fb1 DL |
84 | /** |
85 | * Helper function that returns a random long value. The main purpose of | |
86 | * this function is to hide a `random()` call that gets flagged by coverity | |
87 | * scan and put it into one place. | |
88 | * | |
89 | * The main usage of this function should be for generating jitter or weak | |
90 | * random values for simple purposes. | |
91 | * | |
92 | * See 'man 3 random' for more information. | |
93 | * | |
94 | * \returns random long integer. | |
95 | */ | |
96 | static inline long frr_weak_random(void) | |
97 | { | |
98 | /* coverity[dont_call] */ | |
99 | return random(); | |
100 | } | |
5920b3eb | 101 | |
5e244469 RW |
102 | #ifdef __cplusplus |
103 | } | |
104 | #endif | |
105 | ||
718e3744 | 106 | #endif /* _ZEBRA_NETWORK_H */ |