From: Roy Marples Date: Wed, 21 May 2014 23:07:52 +0000 (+0000) Subject: Source now compiles on Solaris, just missing the if-sun.c support so X-Git-Tag: v6.4.0~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=26c177737ee4c0c6dbe0bd33208a25574073c4b1;p=thirdparty%2Fdhcpcd.git Source now compiles on Solaris, just missing the if-sun.c support so linking fails. --- diff --git a/Makefile b/Makefile index 082dd314..b68ec718 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ SRCS+= if.c if-options.c script.c SRCS+= dhcp-common.c CFLAGS?= -O2 -CSTD?= c99 MKDIRS= TOP?= . include ${TOP}/iconfig.mk +CSTD?= c99 CFLAGS+= -std=${CSTD} SRCS+= ${DHCPCD_SRCS} diff --git a/auth.c b/auth.c index c33e565f..81817848 100644 --- a/auth.c +++ b/auth.c @@ -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 @@ get_next_rdm_monotonic_counter(struct auth *auth) { FILE *fp; uint64_t rdm; +#ifdef LOCK_EX int flocked; +#endif fp = fopen(RDM_MONOFILE, "r+"); if (fp == NULL) { @@ -395,10 +402,14 @@ get_next_rdm_monotonic_counter(struct auth *auth) 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 @@ get_next_rdm_monotonic_counter(struct auth *auth) /* report error? */ } fflush(fp); +#ifdef LOCK_EX if (flocked == 0) flock(fileno(fp), LOCK_UN); +#endif fclose(fp); return rdm; } diff --git a/common.c b/common.c index dfb4f697..b90027aa 100644 --- a/common.c +++ b/common.c @@ -30,7 +30,9 @@ # define _GNU_SOURCE #endif -#include +#ifndef __sun +# include +#endif #ifdef __APPLE__ # include diff --git a/common.h b/common.h index 59473fa2..5a545027 100644 --- a/common.h +++ b/common.h @@ -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) diff --git a/compat/dprintf.c b/compat/dprintf.c new file mode 100644 index 00000000..db43fdd2 --- /dev/null +++ b/compat/dprintf.c @@ -0,0 +1,55 @@ +/* + * dhcpcd - DHCP client daemon + * Copyright (c) 2006-2014 Roy Marples + * 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 +#include +#include +#include + +#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; +} diff --git a/compat/dprintf.h b/compat/dprintf.h new file mode 100644 index 00000000..f44d13a8 --- /dev/null +++ b/compat/dprintf.h @@ -0,0 +1,32 @@ +/* + * dhcpcd - DHCP client daemon + * Copyright (c) 2006-2014 Roy Marples + * 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 diff --git a/configure b/configure index d01914ad..9e9c25cc 100755 --- a/configure +++ b/configure @@ -301,7 +301,7 @@ if [ -e "$LDELF" ]; then 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-prototypes -Wmissing-declarations 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 @@ 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 @@ -366,6 +371,11 @@ kfreebsd*) 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 @@ int main(void) { 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 @@ fi rm -f _clock_gettime.c _clock_gettime $abort && exit 1 +printf "Testing for inet_ntoa ... " +cat <_inet_ntoa.c +#include +#include +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 <_arc4random.c @@ -519,6 +555,27 @@ if [ "$STRLCPY" = no ]; then echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H fi +if [ -z "$DPRINTF" ]; then + printf "Testing for dprintf ... " + cat <_dprintf.c +#include +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 <_queue.c diff --git a/control.c b/control.c index 958a32f6..d902b197 100644 --- a/control.c +++ b/control.c @@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#include #include #include @@ -126,7 +127,7 @@ control_handle(void *arg) } 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 @@ make_sock(struct dhcpcd_ctx *ctx, struct sockaddr_un *sun, const char *ifname) 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 @@ control_stop(struct dhcpcd_ctx *ctx) 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; diff --git a/dhcp.c b/dhcp.c index 2d0fe3cc..e03c3478 100644 --- a/dhcp.c +++ b/dhcp.c @@ -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; diff --git a/dhcpcd-embedded.c.in b/dhcpcd-embedded.c.in new file mode 100755 index 00000000..3c0a7a7b --- /dev/null +++ b/dhcpcd-embedded.c.in @@ -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 + * 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 + +const char * const dhcpcd_embedded_conf[] = { diff --git a/dhcpcd.c b/dhcpcd.c index 5e142009..ac09d276 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1139,7 +1139,11 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) 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 @@ main(int argc, char **argv) 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) diff --git a/genembedc b/genembedc index f565d33e..5bd7b6f6 100755 --- a/genembedc +++ b/genembedc @@ -4,45 +4,7 @@ set -e : ${TOOL_SED:=sed} CONF=${1:-dhcpcd-definitions.conf} -cat < - * 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 - -const char * const dhcpcd_embedded_conf[] = { -EOF - +cat dhcpcd-embedded.c.in $TOOL_SED \ -e 's/#.*$//' \ -e '/^$/d' \ diff --git a/if.c b/if.c index add301ea..0aad1f6b 100644 --- a/if.c +++ b/if.c @@ -341,15 +341,23 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) 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; diff --git a/ipv6nd.h b/ipv6nd.h index 6c52c1fd..f29065d9 100644 --- a/ipv6nd.h +++ b/ipv6nd.h @@ -103,7 +103,7 @@ void ipv6nd_neighbour(struct dhcpcd_ctx *, struct in6_addr *, int); #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