linking fails.
SRCS+= dhcp-common.c
CFLAGS?= -O2
-CSTD?= c99
MKDIRS=
TOP?= .
include ${TOP}/iconfig.mk
+CSTD?= c99
CFLAGS+= -std=${CSTD}
SRCS+= ${DHCPCD_SRCS}
#include "dhcp6.h"
#include "dhcpcd.h"
+#ifdef __sun
+#define htonll
+#define ntohll
+#endif
+
#ifndef htonll
#if (BYTE_ORDER == LITTLE_ENDIAN)
static inline uint64_t
{
FILE *fp;
uint64_t rdm;
+#ifdef LOCK_EX
int flocked;
+#endif
fp = fopen(RDM_MONOFILE, "r+");
if (fp == NULL) {
fp = fopen(RDM_MONOFILE, "w");
if (fp == NULL)
return ++auth->last_replay; /* report error? */
+#ifdef LOCK_EX
flocked = flock(fileno(fp), LOCK_EX);
+#endif
rdm = 0;
} else {
+#ifdef LOCK_EX
flocked = flock(fileno(fp), LOCK_EX);
+#endif
if (fscanf(fp, "0x%016" PRIu64, &rdm) != 1)
rdm = 0; /* truncated? report error? */
}
/* report error? */
}
fflush(fp);
+#ifdef LOCK_EX
if (flocked == 0)
flock(fileno(fp), LOCK_UN);
+#endif
fclose(fp);
return rdm;
}
# define _GNU_SOURCE
#endif
-#include <sys/cdefs.h>
+#ifndef __sun
+# include <sys/cdefs.h>
+#endif
#ifdef __APPLE__
# include <mach/mach_time.h>
#define HOSTNAME_MAX_LEN 250 /* 255 - 3 (FQDN) - 2 (DNS enc) */
#endif
+#ifndef MIN
+#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
+#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
+#endif
+
#define UNCONST(a) ((void *)(unsigned long)(const void *)(a))
#define STRINGIFY(a) #a
#define TOSTRING(a) STRINGIFY(a)
--- /dev/null
+/*
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#include "dprintf.h"
+
+int
+dprintf(int fd, const char *fmt, ...)
+{
+ int e;
+ FILE *fp;
+ va_list va;
+
+ if ((e = dup(fd)) == -1)
+ return -1;
+
+ if ((fp = fdopen(e, "r+")) == NULL) {
+ close(e);
+ return -1;
+ }
+
+ va_start(va, fmt);
+ e = vfprintf(fp, fmt, va);
+ va_end(va);
+ fclose(fp);
+ return e;
+}
--- /dev/null
+/*
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef DPRINTF_H
+#define DPRINTF_H
+
+int dprintf(int, const char *, ...);
+#endif
fi
case "$OS" in
-linux*) ;;
+linux*|sunos*) ;;
*)
if ! [ -x "$LDELF" -o -x /libexec/ld-elf.so.[0-9]* ] && \
[ -z "$PREFIX" -o "$PREFIX" = "/" ]
CFLAGS+= -Wmissing-noreturn -Wmissing-format-attribute
CFLAGS+= -Wnested-externs
CFLAGS+= -Winline -Wwrite-strings -Wcast-align -Wcast-qual
-CFLAGS+= -Wpointer-arith -Wstrict-overflow
+CFLAGS+= -Wpointer-arith
CFLAGS+= -Wdeclaration-after-statement
CFLAGS+= -Wconversion
EOF
mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers
*) echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK;;
esac
+
+ case "$OS" in
+ sunos*);;
+ *) echo "CFLAGS+= -Wstrict-overflow" >>$CONFIG_MF;;
+ esac
fi
if [ -z "$EMBEDDED" -o "$EMBEDDED" = yes ]; then
echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK
echo "COMPAT_SRCS+= compat/linkaddr.c" >>$CONFIG_MK
;;
+sunos*)
+# echo "CSTD= gnu99" >>$CONFIG_MK
+ echo "CPPFLAGS+= -D_XPG4_2 -D__EXTENSIONS__ -DBSD_COMP" \
+ >>$CONFIG_MK
+ ;;
*)
echo "DHCPCD_SRCS+= if-bsd.c" >>$CONFIG_MK
;;
EOF
if $XCC _getifaddrs.c -o _getifaddrs 2>/dev/null; then
echo "yes"
+elif $XCC _getifaddrs.c -o _getifaddrs -lsocket >/dev/null; then
+ echo "yes (-lsocket)"
+ echo "LDADD+= -lsocket" >>$CONFIG_MK
else
echo "no"
echo "libc support for getifaddrs is required - aborting" >&2
rm -f _clock_gettime.c _clock_gettime
$abort && exit 1
+printf "Testing for inet_ntoa ... "
+cat <<EOF >_inet_ntoa.c
+#include <netinet/in.h>
+#include <arpa/inet.h>
+int main(void) {
+ struct in_addr in;
+ inet_ntoa(in);
+ return 0;
+}
+EOF
+if $XCC _inet_ntoa.c -o _inet_ntoa 2>/dev/null; then
+ echo "yes"
+elif $XCC _inet_ntoa.c -lnsl -o _inet_ntoa 2>/dev/null; then
+ echo "yes (-lnsl)"
+ echo "LDADD+= -lnsl" >>$CONFIG_MK
+else
+ echo "no"
+ echo "libc support for inet_ntoa is required - aborting" >&2
+ abort=true
+fi
+rm -f _inet_ntoa.c _inet_ntoa
+$abort && exit 1
+
if [ -z "$ARC4RANDOM" ]; then
printf "Testing for arc4random ... "
cat <<EOF >_arc4random.c
echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H
fi
+if [ -z "$DPRINTF" ]; then
+ printf "Testing for dprintf ... "
+ cat <<EOF >_dprintf.c
+#include <stdio.h>
+int main(void) {
+ return dprintf(0, "%d", 0);
+}
+EOF
+ if $XCC _dprintf.c -o _dprintf 2>/dev/null; then
+ DPRINTF=yes
+ else
+ DPRINTF=no
+ fi
+ echo "$DPRINTF"
+ rm -f _dprintf.c _dprintf
+fi
+if [ "$DPRINTF" = no ]; then
+ echo "COMPAT_SRCS+= compat/dprintf.c" >>$CONFIG_MK
+ echo "#include \"compat/dprintf.h\"" >>$CONFIG_H
+fi
+
if [ -z "$TAILQ_FOREACH_SAFE" ]; then
printf "Testing for TAILQ_FOREACH_SAFE ... "
cat <<EOF >_queue.c
* SUCH DAMAGE.
*/
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
}
static socklen_t
-make_sock(struct dhcpcd_ctx *ctx, struct sockaddr_un *sun, const char *ifname)
+make_sock(struct dhcpcd_ctx *ctx, struct sockaddr_un *sa, const char *ifname)
{
#ifdef SOCK_CLOEXEC
return 0;
}
#endif
- memset(sun, 0, sizeof(*sun));
- sun->sun_family = AF_UNIX;
- snprintf(sun->sun_path, sizeof(sun->sun_path), CONTROLSOCKET,
+ memset(sa, 0, sizeof(*sa));
+ sa->sun_family = AF_UNIX;
+ snprintf(sa->sun_path, sizeof(sa->sun_path), CONTROLSOCKET,
ifname ? "-" : "", ifname ? ifname : "");
- strlcpy(ctx->control_sock, sun->sun_path, sizeof(ctx->control_sock));
- return (socklen_t)SUN_LEN(sun);
+ strlcpy(ctx->control_sock, sa->sun_path, sizeof(ctx->control_sock));
+ return (socklen_t)SUN_LEN(sa);
}
int
control_start(struct dhcpcd_ctx *ctx, const char *ifname)
{
- struct sockaddr_un sun;
+ struct sockaddr_un sa;
socklen_t len;
- if ((len = make_sock(ctx, &sun, ifname)) == 0)
+ if ((len = make_sock(ctx, &sa, ifname)) == 0)
return -1;
unlink(ctx->control_sock);
- if (bind(ctx->control_fd, (struct sockaddr *)&sun, len) == -1 ||
+ if (bind(ctx->control_fd, (struct sockaddr *)&sa, len) == -1 ||
chmod(ctx->control_sock,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1 ||
(ctx->control_group &&
int
control_open(struct dhcpcd_ctx *ctx, const char *ifname)
{
- struct sockaddr_un sun;
+ struct sockaddr_un sa;
socklen_t len;
- if ((len = make_sock(ctx, &sun, ifname)) == 0)
+ if ((len = make_sock(ctx, &sa, ifname)) == 0)
return -1;
- if (connect(ctx->control_fd, (struct sockaddr *)&sun, len) == -1) {
+ if (connect(ctx->control_fd, (struct sockaddr *)&sa, len) == -1) {
close(ctx->control_fd);
ctx->control_fd = -1;
return -1;
#define RELEASE_DELAY_S 0
#define RELEASE_DELAY_NS 10000000
+#ifndef IPDEFTTL
+#define IPDEFTTL 64 /* RFC1340 */
+#endif
+
struct dhcp_op {
uint8_t value;
const char *name;
--- /dev/null
+/*
+ * DO NOT EDIT
+ * Automatically generated from dhcpcd-embedded.conf
+ * Ths allows us to simply generate DHCP structure without any C programming
+ */
+
+/*
+ * dhcpcd - DHCP client daemon
+ * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+
+const char * const dhcpcd_embedded_conf[] = {
siga = NULL;
#endif
closefrom(3);
+#ifdef LOG_PERROR
openlog(PACKAGE, LOG_PERROR | LOG_PID, LOG_DAEMON);
+#else
+ openlog(PACKAGE, LOG_PID, LOG_DAEMON);
+#endif
setlogmask(LOG_UPTO(LOG_INFO));
/* Test for --help and --version */
if (ctx.pid_fd == -1)
syslog(LOG_ERR, "open `%s': %m", pidfile);
else {
+#ifdef LOCK_EX
/* Lock the file so that only one instance of dhcpcd
* runs on an interface */
if (flock(ctx.pid_fd, LOCK_EX | LOCK_NB) == -1) {
ctx.pid_fd = -1;
goto exit_failure;
}
+#endif
#ifndef O_CLOEXEC
if (fcntl(ctx.pid_fd, F_GETFD, &opt) == -1 ||
fcntl(ctx.pid_fd, F_SETFD, opt | FD_CLOEXEC) == -1)
: ${TOOL_SED:=sed}
CONF=${1:-dhcpcd-definitions.conf}
-cat <<EOF
-/*
- * DO NOT EDIT
- * Automatically generated from dhcpcd-embedded.conf
- * Ths allows us to simply generate DHCP structure without any C programming
- */
-
-/*
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2013 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <unistd.h>
-
-const char * const dhcpcd_embedded_conf[] = {
-EOF
-
+cat dhcpcd-embedded.c.in
$TOOL_SED \
-e 's/#.*$//' \
-e '/^$/d' \
ifp->index = sdl->sdl_index;
sdl_type = sdl->sdl_type;
switch(sdl->sdl_type) {
+#ifdef IFT_BRIDGE
case IFT_BRIDGE: /* FALLTHROUGH */
+#endif
+#ifdef IFT_L2VLAN
case IFT_L2VLAN: /* FALLTHOUGH */
+#endif
+#ifdef IFT_L3IPVLAN
case IFT_L3IPVLAN: /* FALLTHROUGH */
+#endif
case IFT_ETHER:
ifp->family = ARPHRD_ETHER;
break;
+#ifdef IFT_IEEE1394
case IFT_IEEE1394:
ifp->family = ARPHRD_IEEE1394;
break;
+#endif
#ifdef IFT_INFINIBAND
case IFT_INFINIBAND:
ifp->family = ARPHRD_INFINIBAND;
#define ipv6nd_startrs(a) {}
#define ipv6nd_addrexists(a, b) (0)
#define ipv6nd_free(a)
-#define ipv6nd_has_ra(a) (0)
+#define ipv6nd_hasra(a) (0)
#define ipv6nd_drop(a)
#endif