From: Roy Marples Date: Thu, 5 Jun 2014 13:53:20 +0000 (+0000) Subject: be32enc is missing on OpenBSD, so provide a configure test. X-Git-Tag: v6.4.0~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6c9c45832452e256002b65fb178b1e49ac3d27a2;p=thirdparty%2Fdhcpcd.git be32enc is missing on OpenBSD, so provide a configure test. Fix compile on OpenBSD. --- diff --git a/common.h b/common.h index 94c207e8..f515162e 100644 --- a/common.h +++ b/common.h @@ -107,47 +107,6 @@ # endif #endif -#ifndef BSD -static inline void -be32enc(uint8_t *buf, uint32_t u) -{ - - buf[0] = (uint8_t)((u >> 24) & 0xff); - buf[1] = (uint8_t)((u >> 16) & 0xff); - buf[2] = (uint8_t)((u >> 8) & 0xff); - buf[3] = (uint8_t)(u & 0xff); -} - -static inline void -be64enc(uint8_t *buf, uint64_t u) -{ - - be32enc(buf, (uint32_t)(u >> 32)); - be32enc(buf + sizeof(uint32_t), (uint32_t)(u & 0xffffffffULL)); -} - -static inline uint16_t -be16dec(const uint8_t *buf) -{ - - return (uint16_t)(buf[0] << 8 | buf[1]); -} - -static inline uint32_t -be32dec(const uint8_t *buf) -{ - - return (uint32_t)((uint32_t)be16dec(buf) << 16 | be16dec(buf + 2)); -} - -static inline uint64_t -be64dec(const uint8_t *buf) -{ - - return (uint64_t)((uint64_t)be32dec(buf) << 32 | be32dec(buf + 4)); -} -#endif - void get_line_free(void); const char *get_hostname(char *, size_t, int); extern int clock_monotonic; diff --git a/compat/endian.h b/compat/endian.h new file mode 100644 index 00000000..3a997a57 --- /dev/null +++ b/compat/endian.h @@ -0,0 +1,71 @@ +/* + * 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 ENDIAN_H +#define ENDIAN_H + +#include + +static inline void +be32enc(uint8_t *buf, uint32_t u) +{ + + buf[0] = (uint8_t)((u >> 24) & 0xff); + buf[1] = (uint8_t)((u >> 16) & 0xff); + buf[2] = (uint8_t)((u >> 8) & 0xff); + buf[3] = (uint8_t)(u & 0xff); +} + +static inline void +be64enc(uint8_t *buf, uint64_t u) +{ + + be32enc(buf, (uint32_t)(u >> 32)); + be32enc(buf + sizeof(uint32_t), (uint32_t)(u & 0xffffffffULL)); +} + +static inline uint16_t +be16dec(const uint8_t *buf) +{ + + return (uint16_t)(buf[0] << 8 | buf[1]); +} + +static inline uint32_t +be32dec(const uint8_t *buf) +{ + + return (uint32_t)((uint32_t)be16dec(buf) << 16 | be16dec(buf + 2)); +} + +static inline uint64_t +be64dec(const uint8_t *buf) +{ + + return (uint64_t)((uint64_t)be32dec(buf) << 32 | be32dec(buf + 4)); +} +#endif diff --git a/configure b/configure index 03e745a9..37786088 100755 --- a/configure +++ b/configure @@ -716,7 +716,7 @@ case "$POLLTS" in yes) ;; ppoll) - echo "#define pollts ppoll" >>$CONFIG_H + echo "#define pollts ppoll" >>$CONFIG_H ;; pselect) echo "COMPAT_SRCS+= compat/pselect.c" >>$CONFIG_MK @@ -751,6 +751,25 @@ if [ "$LOG_PERROR" = no ]; then echo "#define syslog psyslog" >>$CONFIG_H fi +if [ -z "$BE64ENC" ]; then + printf "Testing for be64enc ... " + cat <_be64enc.c +#include +int main(void) { + be64enc(NULL, 0); +} +EOF + if $XCC _be64enc.c -o _be64enc 2>/dev/null; then + BE64ENC=yes + else + BE64ENC=no + fi + echo "$BE64ENC" +fi +if [ "$BE64ENC" == no ]; then + echo "#include \"compat/endian.h\"" >>$CONFIG_H +fi + if [ -z "$MD5" ]; then MD5_LIB= printf "Testing for MD5Init ... " diff --git a/ipv6.c b/ipv6.c index 1b2300ec..cdbfb1f0 100644 --- a/ipv6.c +++ b/ipv6.c @@ -30,9 +30,10 @@ #include #include +#include #include -#include #include +#include #ifdef __linux__ # include /* for systems with broken headers */