1 /* SPDX-License-Identifier: BSD-2-Clause */
3 * dhcpcd - DHCP client daemon
4 * Copyright (c) 2006-2023 Roy Marples <roy@marples.name>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
34 #include <sys/types.h>
38 /* Define eloop queues here, as other apps share eloop.h */
39 #define ELOOP_DHCPCD 1 /* default queue */
42 #define ELOOP_IPV4LL 4
44 #define ELOOP_IPV6ND 6
45 #define ELOOP_IPV6RA_EXPIRE 7
49 #ifndef HOSTNAME_MAX_LEN
50 #define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
54 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
55 #define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
58 #define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
59 #define STRINGIFY(a) #a
60 #define TOSTRING(a) STRINGIFY(a)
61 #define UNUSED(a) (void)(a)
63 #define ROUNDUP4(a) (1 + (((a) - 1) | 3))
64 #define ROUNDUP8(a) (1 + (((a) - 1) | 7))
66 /* Some systems don't define timespec macros */
68 #define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)
69 #define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
72 #if __GNUC__ > 2 || defined(__INTEL_COMPILER)
74 # define __packed __attribute__((__packed__))
77 # define __unused __attribute__((__unused__))
88 /* Needed for rbtree(3) compat */
92 #ifndef __predict_false
94 # define __predict_true(exp) __builtin_expect((exp) != 0, 1)
95 # define __predict_false(exp) __builtin_expect((exp) != 0, 0)
97 # define __predict_true(exp) (exp)
98 # define __predict_false(exp) (exp)
101 #ifndef __BEGIN_DECLS
102 # if defined(__cplusplus)
103 # define __BEGIN_DECLS extern "C" {
104 # define __END_DECLS };
105 # else /* __BEGIN_DECLS */
106 # define __BEGIN_DECLS
108 # endif /* __BEGIN_DECLS */
109 #endif /* __BEGIN_DECLS */
111 #ifndef __fallthrough
113 # define __fallthrough __attribute__((fallthrough))
115 # define __fallthrough
120 * Compile Time Assertion.
124 # define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__)
126 # define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__)
127 # define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \
130 # define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z)
131 # define __CTASSERT1(x, y, z) typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] __unused
135 # define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
138 /* We don't really need this as our supported systems define __restrict
139 * automatically for us, but it is here for completeness. */
141 # if defined(__lint__)
143 # elif __STDC_VERSION__ >= 199901L
144 # define __restrict restrict
145 # elif !(2 < __GNUC__ || (2 == __GNU_C && 95 <= __GNUC_VERSION__))
150 const char *hwaddr_ntoa(const void *, size_t, char *, size_t);
151 size_t hwaddr_aton(uint8_t *, const char *);
152 ssize_t
readfile(const char *, void *, size_t);
153 ssize_t
writefile(const char *, mode_t
, const void *, size_t);
154 int filemtime(const char *, time_t *);
155 char *get_line(char ** __restrict
, ssize_t
* __restrict
);
156 int is_root_local(void);