]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Rework the arp code again so that we don't link to librt on Linux.
authorRoy Marples <roy@marples.name>
Mon, 20 Aug 2007 16:33:09 +0000 (16:33 +0000)
committerRoy Marples <roy@marples.name>
Mon, 20 Aug 2007 16:33:09 +0000 (16:33 +0000)
ChangeLog
Makefile
arp.c
common.c
common.h

index 4b5e2e8e410eb1b4f3ef024d5b389195ac948b61..cdbff48830c0538df11f6cd4f62034b471ba6856 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+dhcpcd-3.1.5
+Rework the arp code again so that we don't link to librt on Linux.
 Thanks to regenrecht for reporting the below three overflows:-
  Fix a potential buffer overflow in hwaddr_ntoa if length > 42.
  Fix a potential heap overflow in decode_CSR when CIDR > 32.
index 4f6042342f2d5e3b27da569a2eaafbcfcc9d4bbc..b9a3dae1c99760a63f8aa25ef81331287c06441a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -49,16 +49,11 @@ dhcpcd_H = version.h
 dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \
                info.o interface.o ipv4ll.o logger.o signals.o socket.o
 
-# These are nasty hacks to work out what libs we need to link to
-# We require librt for glibc bases systems
-LIBRT != ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt" || exit 0
-LIBRT ?= $(shell ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt")
-
 # Darwin needs this, but we have no way of detecting this atm
 #LIBRESOLV = -lresolv
 
 dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS)
-       $(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(LIBRT) $(LIBRESOLV) -o dhcpcd
+       $(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(LIBRESOLV) -o dhcpcd
 
 version.h:
        echo '#define VERSION "$(VERSION)"' > version.h
diff --git a/arp.c b/arp.c
index ce2ba417bb5b879bc785331a8e3c86b17832f361..56c04e153ea799b8ff17d4983c11ed2f827fe251 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -103,8 +103,11 @@ int arp_claim (interface_t *iface, struct in_addr address)
        int nprobes = 0;
        int nclaims = 0;
        struct in_addr null_address;
+
+#ifdef HAVE_GET_TIME
        struct timeval stopat;
        struct timeval now;
+#endif
 
        if (! iface)
                return (-1);
@@ -167,21 +170,32 @@ int arp_claim (interface_t *iface, struct in_addr address)
                                break;
                        }
 
+
+#ifdef HAVE_GET_TIME
                        /* Setup our stop time */
                        if (get_time (&stopat) != 0)
                                break;
                        stopat.tv_usec += timeout;
+#endif
 
                        continue;
                }
 
-               /* We maybe ARP flooded, so check our time */
+               /* Check for ARP floods */
+#ifdef __linux__
+               /* Linux does modify the tv struct, otherwise we would have to link
+                * into librt to use get get_time function */
+               timeout = tv.tv_usec;
+               if (timeout <= 0)
+                       continue;
+#else
                if (get_time (&now) != 0)
                        break;
                if (timercmp (&now, &stopat, >)) {
                        timeout = 0;
                        continue;
                }
+#endif
 
                if (! FD_ISSET (iface->fd, &rset))
                        continue;
index 2eb4e9376c2644908a5b2cdd92a3ecd01701ea5a..b0cdb4e789406887a5fec4f3ef848ad73f6ddae8 100644 (file)
--- a/common.c
+++ b/common.c
@@ -76,12 +76,54 @@ size_t strlcpy (char *dst, const char *src, size_t size)
 #  endif
 #endif
 
+/* This requires us to link to rt on glibc, so we use sysinfo instead */
+#ifdef __linux__
+#include <sys/sysinfo.h>
+long uptime (void)
+{
+       struct sysinfo info;
+
+       sysinfo (&info);
+       return info.uptime;
+}
+#elif __APPLE__
+/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
+long uptime (void)
+{
+       struct timeval tv;
+       static long start = 0;
+
+       if (gettimeofday (&tv, NULL) == -1) {
+               logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
+               return -1;
+       }
+
+       if (start == 0)
+               start = tv.tv_sec;
+
+       return tv.tv_sec - start;
+}
+#else
+long uptime (void)
+{
+       struct timespec tp;
+
+       if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
+               logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
+               return -1;
+       }
+
+       return tp.tv_sec;
+}
+#endif
+
 /* Handy function to get the time.
  * We only care about time advancements, not the actual time itself
  * Which is why we use CLOCK_MONOTONIC, but it is not available on all
  * platforms
  */
-#ifdef CLOCK_MONOTONIC
+#ifdef HAVE_GET_TIME 
+# ifdef CLOCK_MONOTONIC
 int get_time (struct timeval *tp)
 {
        struct timespec ts;
@@ -95,19 +137,7 @@ int get_time (struct timeval *tp)
        tp->tv_usec = ts.tv_nsec / 1000;
        return (0);
 }
-
-long uptime (void)
-{
-       struct timespec tp;
-
-       if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
-               logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
-               return (-1);
-       }
-
-       return (tp.tv_sec);
-}
-#else
+# else
 int get_time (struct timeval *tp)
 {
        if (gettimeofday (&tp, NULL) == -1) {
@@ -116,22 +146,7 @@ int get_time (struct timeval *tp)
        }
        return (0);
 }
-
-long uptime (void)
-{
-       struct timeval tv;
-       static long start = 0;
-
-       if (gettimeofday (&tv, NULL) == -1) {
-               logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
-               return (-1);
-       }
-
-       if (start == 0)
-               start = tv.tv_sec;
-
-       return (tv.tv_sec - start);
-}
+# endif
 #endif
 
 void *xmalloc (size_t s)
index 79940997db0ad2166c9283eed377d30297b00b77..b0a308df65b6d5c6173fc4bf5cfe744558cc49e1 100644 (file)
--- a/common.h
+++ b/common.h
@@ -35,9 +35,11 @@ size_t strlcpy (char *dst, const char *src, size_t size);
 
 #ifdef __linux__
 void srandomdev (void);
+#else
+#define HAVE_GET_TIME
+int get_time (struct timeval *tp);
 #endif
 
-int get_time (struct timeval *tp);
 long uptime (void);
 void *xmalloc (size_t size);
 char *xstrdup (const char *str);