]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
be32enc is missing on OpenBSD, so provide a configure test.
authorRoy Marples <roy@marples.name>
Thu, 5 Jun 2014 13:53:20 +0000 (13:53 +0000)
committerRoy Marples <roy@marples.name>
Thu, 5 Jun 2014 13:53:20 +0000 (13:53 +0000)
Fix compile on OpenBSD.

common.h
compat/endian.h [new file with mode: 0644]
configure
ipv6.c

index 94c207e8096bc07a22f2daf1d318b30f8045a5bb..f515162e4f76f1fc9d6134a5566e1debd4a14aa3 100644 (file)
--- a/common.h
+++ b/common.h
 # 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 (file)
index 0000000..3a997a5
--- /dev/null
@@ -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
index 03e745a973f8c925d3a5a05507a8e4a25c7230d7..377860888247eb8c060f701d431f2db35a23aca9 100755 (executable)
--- 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 <<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 ... "
diff --git a/ipv6.c b/ipv6.c
index 1b2300ec756e84d3cd32aa0e3367aafd8a0d9799..cdbfb1f078e8b68c511b9ba102bebf00783f7a5c 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
 #include <sys/socket.h>
 #include <sys/stat.h>
 
+#include <net/if.h>
 #include <net/route.h>
-#include <netinet/if_ether.h>
 #include <netinet/in.h>
+#include <netinet/if_ether.h>
 
 #ifdef __linux__
 #  include <asm/types.h> /* for systems with broken headers */