Mercurial > hg > dhcpcd
changeset 2522:b51f8624a660 draft
be32enc is missing on OpenBSD, so provide a configure test.
Fix compile on OpenBSD.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Thu, 05 Jun 2014 13:53:20 +0000 |
| parents | 1bea2300e658 |
| children | ae77ab271a92 |
| files | common.h compat/endian.h configure ipv6.c |
| diffstat | 4 files changed, 93 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/common.h Thu Jun 05 13:03:49 2014 +0000 +++ b/common.h Thu Jun 05 13:53:20 2014 +0000 @@ -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;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compat/endian.h Thu Jun 05 13:53:20 2014 +0000 @@ -0,0 +1,71 @@ +/* + * 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 ENDIAN_H +#define ENDIAN_H + +#include <stdint.h> + +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
--- a/configure Thu Jun 05 13:03:49 2014 +0000 +++ b/configure Thu Jun 05 13:53:20 2014 +0000 @@ -716,7 +716,7 @@ 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 @@ echo "#define syslog psyslog" >>$CONFIG_H fi +if [ -z "$BE64ENC" ]; then + printf "Testing for be64enc ... " + cat <<EOF >_be64enc.c +#include <sys/endian.h> +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 ... "
--- a/ipv6.c Thu Jun 05 13:03:49 2014 +0000 +++ b/ipv6.c Thu Jun 05 13:53:20 2014 +0000 @@ -30,9 +30,10 @@ #include <sys/socket.h> #include <sys/stat.h> +#include <net/if.h> #include <net/route.h> +#include <netinet/in.h> #include <netinet/if_ether.h> -#include <netinet/in.h> #ifdef __linux__ # include <asm/types.h> /* for systems with broken headers */
