]>
git.proxmox.com Git - mirror_frr.git/blob - lib/network.h
2 * Network library header.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
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
22 #ifndef _ZEBRA_NETWORK_H
23 #define _ZEBRA_NETWORK_H
25 #ifdef HAVE_SYS_ENDIAN_H
26 #include <sys/endian.h>
36 /* Both readn and writen are deprecated and will be removed. They are not
37 suitable for use with non-blocking file descriptors.
39 extern int readn(int, uint8_t *, int);
40 extern int writen(int, const uint8_t *, int);
42 /* Set the file descriptor to use non-blocking I/O. Returns 0 for success,
44 extern int set_nonblocking(int fd
);
46 extern int set_cloexec(int fd
);
48 /* Does the I/O error indicate that the operation should be retried later? */
49 #define ERRNO_IO_RETRY(EN) \
50 (((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
52 extern float htonf(float);
53 extern float ntohf(float);
55 /* force type for be64toh/htobe64 to be uint64_t, *without* a direct cast
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(...)); }
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.)
66 /* zap system definitions... */
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; })
81 #error nobody expects the endianish inquisition. check OS endian.h headers.
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.
89 * The main usage of this function should be for generating jitter or weak
90 * random values for simple purposes.
92 * See 'man 3 random' for more information.
94 * \returns random long integer.
96 static inline long frr_weak_random(void)
98 /* coverity[dont_call] */
106 #endif /* _ZEBRA_NETWORK_H */