changeset 2492:12585d26b91a draft

Source now compiles on Solaris, just missing the if-sun.c support so linking fails.
author Roy Marples <roy@marples.name>
date Wed, 21 May 2014 23:07:52 +0000
parents 6ec3f4009bb4
children ec2af7c0334d
files Makefile auth.c common.c common.h compat/dprintf.c compat/dprintf.h configure control.c dhcp.c dhcpcd-embedded.c.in dhcpcd.c genembedc if.c ipv6nd.h
diffstat 14 files changed, 237 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue May 20 08:54:00 2014 +0000
+++ b/Makefile	Wed May 21 23:07:52 2014 +0000
@@ -6,12 +6,12 @@
 SRCS+=		dhcp-common.c
 
 CFLAGS?=	-O2
-CSTD?=		c99
 MKDIRS=
 
 TOP?=		.
 include ${TOP}/iconfig.mk
 
+CSTD?=		c99
 CFLAGS+=	-std=${CSTD}
 
 SRCS+=		${DHCPCD_SRCS}
--- a/auth.c	Tue May 20 08:54:00 2014 +0000
+++ b/auth.c	Wed May 21 23:07:52 2014 +0000
@@ -44,6 +44,11 @@
 #include "dhcp6.h"
 #include "dhcpcd.h"
 
+#ifdef __sun
+#define htonll
+#define ntohll
+#endif
+
 #ifndef htonll
 #if (BYTE_ORDER == LITTLE_ENDIAN)
 static inline uint64_t
@@ -386,7 +391,9 @@
 {
 	FILE *fp;
 	uint64_t rdm;
+#ifdef LOCK_EX
 	int flocked;
+#endif
 
 	fp = fopen(RDM_MONOFILE, "r+");
 	if (fp == NULL) {
@@ -395,10 +402,14 @@
 		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? */
 	}
@@ -416,8 +427,10 @@
 		/* report error? */
 	}
 	fflush(fp);
+#ifdef LOCK_EX
 	if (flocked == 0)
 		flock(fileno(fp), LOCK_UN);
+#endif
 	fclose(fp);
 	return rdm;
 }
--- a/common.c	Tue May 20 08:54:00 2014 +0000
+++ b/common.c	Wed May 21 23:07:52 2014 +0000
@@ -30,7 +30,9 @@
 #  define _GNU_SOURCE
 #endif
 
-#include <sys/cdefs.h>
+#ifndef __sun
+#  include <sys/cdefs.h>
+#endif
 
 #ifdef __APPLE__
 #  include <mach/mach_time.h>
--- a/common.h	Tue May 20 08:54:00 2014 +0000
+++ b/common.h	Wed May 21 23:07:52 2014 +0000
@@ -38,6 +38,11 @@
 #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	Thu Jan 01 00:00:00 1970 +0000
+++ b/compat/dprintf.c	Wed May 21 23:07:52 2014 +0000
@@ -0,0 +1,55 @@
+/*
+ * 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	Thu Jan 01 00:00:00 1970 +0000
+++ b/compat/dprintf.h	Wed May 21 23:07:52 2014 +0000
@@ -0,0 +1,32 @@
+/*
+ * 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
--- a/configure	Tue May 20 08:54:00 2014 +0000
+++ b/configure	Wed May 21 23:07:52 2014 +0000
@@ -301,7 +301,7 @@
 fi
 
 case "$OS" in
-linux*) ;;
+linux*|sunos*) ;;
 *)
 	if ! [ -x "$LDELF" -o -x /libexec/ld-elf.so.[0-9]* ] && \
 	    [ -z "$PREFIX" -o "$PREFIX" = "/" ]
@@ -332,7 +332,7 @@
 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
@@ -340,6 +340,11 @@
 	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
@@ -366,6 +371,11 @@
 	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
 	;;
@@ -397,6 +407,9 @@
 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
@@ -426,6 +439,29 @@
 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
@@ -519,6 +555,27 @@
 	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
--- a/control.c	Tue May 20 08:54:00 2014 +0000
+++ b/control.c	Wed May 21 23:07:52 2014 +0000
@@ -25,6 +25,7 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/un.h>
 
@@ -126,7 +127,7 @@
 }
 
 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
@@ -153,24 +154,24 @@
 	        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 &&
@@ -217,12 +218,12 @@
 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;
--- a/dhcp.c	Tue May 20 08:54:00 2014 +0000
+++ b/dhcp.c	Wed May 21 23:07:52 2014 +0000
@@ -82,6 +82,10 @@
 #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	Thu Jan 01 00:00:00 1970 +0000
+++ b/dhcpcd-embedded.c.in	Wed May 21 23:07:52 2014 +0000
@@ -0,0 +1,36 @@
+/*
+ * 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[] = {
--- a/dhcpcd.c	Tue May 20 08:54:00 2014 +0000
+++ b/dhcpcd.c	Wed May 21 23:07:52 2014 +0000
@@ -1139,7 +1139,11 @@
 	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 */
@@ -1392,6 +1396,7 @@
 		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) {
@@ -1400,6 +1405,7 @@
 				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)
--- a/genembedc	Tue May 20 08:54:00 2014 +0000
+++ b/genembedc	Wed May 21 23:07:52 2014 +0000
@@ -4,45 +4,7 @@
 : ${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' \
--- a/if.c	Tue May 20 08:54:00 2014 +0000
+++ b/if.c	Wed May 21 23:07:52 2014 +0000
@@ -341,15 +341,23 @@
 			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;
--- a/ipv6nd.h	Tue May 20 08:54:00 2014 +0000
+++ b/ipv6nd.h	Wed May 21 23:07:52 2014 +0000
@@ -103,7 +103,7 @@
 #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