]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd is reported to work on Darwin :)
authorRoy Marples <roy@marples.name>
Fri, 15 Dec 2006 18:28:54 +0000 (18:28 +0000)
committerRoy Marples <roy@marples.name>
Fri, 15 Dec 2006 18:28:54 +0000 (18:28 +0000)
ChangeLog
Makefile
common.c
configure.c
dhcpcd.h
interface.c
socket.c

index b9e77f96866aecd2059a7f2ebd1b6177a8a68376..09e8006e98a2773b67b211bb5d3c0941bb54c2b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+Dawin is now reported to work.
 cleanmetas now inserts a \ when it finds a ' so we get the proper
 values in our .info files when read by a shell.
 Add new CFLAGS to ensure that the code quality is good.
index 95f17cbcf56d60fcca77f32bfd14747ab545c918..f99035903703014a9ba0d22e3a74446a637c80af 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,8 +34,12 @@ dhcpcd_H = version.h
 dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o \
                interface.o logger.o signals.o socket.o
 
+# By default we don't need to link to anything
+# Except on Darwin where we need -lresolv, so they need to uncomment this
+#dhcpcd_LIBS = -lresolv
+
 dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS)
-       $(CC) $(LDFLAGS) $(dhcpcd_OBJS) -o dhcpcd
+       $(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(dhcpcd_LIBS) -o dhcpcd
 
 version.h:
        echo '#define VERSION "$(VERSION)"' > version.h
index e1f5f5136513f0383edc78d3cb356b67829c174c..5739e4ff83e511f9b79bc5bd2a4a289760738ab1 100644 (file)
--- a/common.c
+++ b/common.c
@@ -37,6 +37,25 @@ long uptime (void)
   sysinfo (&info);
   return info.uptime;
 }
+#elif __APPLE__
+/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
+#include <sys/time.h>
+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
 #include <time.h>
 long uptime (void)
@@ -45,17 +64,17 @@ long uptime (void)
 
   if (clock_gettime(CLOCK_MONOTONIC, &tp) == -1)
     {
-      logger (LOG_ERR, "Unable to get uptime: %s", strerror (errno));
+      logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
       return -1;
     }
 
   return tp.tv_sec;
 }
-#endif /* __linux__ */
+#endif
 
 void *xmalloc (size_t size)
 {
-  register void *value = malloc (size);
+  void *value = malloc (size);
 
   if (value)
     return value;
index d86b8eba43894cff7ab2911e92b0f351eae6c04b..e88bbfb945dfc6b36d005f350c79bfeaa22d8dd6 100644 (file)
@@ -51,14 +51,13 @@ static char *cleanmetas (const char *cstr)
   /* The largest single element we can have is 256 bytes according to the RFC,
      so this buffer size should be safe even if it's all ' */
   char buffer[1024] = {0};
-  register char *c = (char *) cstr;
-  register char *b = buffer;
+  char *b = buffer;
 
   if (! cstr || strlen (cstr) == 0)
       return b;
 
   do
-    if (*c == 39)
+    if (*cstr == 39)
       {
        *b++ = '\'';
        *b++ = '\\';
@@ -66,8 +65,8 @@ static char *cleanmetas (const char *cstr)
        *b++ = '\'';
       }
     else
-      *b++ = *c;
-  while (*c++);
+      *b++ = *cstr;
+  while (*cstr++);
 
   *b++ = 0;
   b = buffer;
@@ -80,8 +79,6 @@ static void exec_script (const char *script, const char *infofile,
 {
   struct stat buf;
   pid_t pid;
-  char *const argc[4] =
-    { (char *) script, (char *) infofile, (char *) arg, NULL };
 
   if (! script || ! infofile || ! arg)
     return;
@@ -100,9 +97,9 @@ static void exec_script (const char *script, const char *infofile,
      causing the script to fail */
   if ((pid = fork ()) == 0)
     {
-      if (execv (script, argc))
+      if (execle (script, script, infofile, arg, NULL, NULL))
        logger (LOG_ERR, "error executing \"%s %s %s\": %s",
-               argc[0], argc[1], argc[2], strerror (errno));
+               script, infofile, arg, strerror (errno));
       exit (0);
     }
   else if (pid == -1)
@@ -161,8 +158,6 @@ static void restore_resolv(const char *ifname)
 {
   struct stat buf;
   pid_t pid;
-  char *const argc[4] =
-    { (char *) RESOLVCONF, (char *) "-d", (char *) ifname, NULL };
 
   if (stat (RESOLVCONF, &buf) < 0)
     return;
@@ -176,9 +171,9 @@ static void restore_resolv(const char *ifname)
      causing the script to fail */
   if ((pid = fork ()) == 0)
     {
-      if (execve (argc[0], argc, NULL))
-       logger (LOG_ERR, "error executing \"%s %s %s\": %s",
-               argc[0], argc[1], argc[2], strerror (errno));
+      if (execle (RESOLVCONF, RESOLVCONF, "-d", ifname, NULL, NULL))
+       logger (LOG_ERR, "error executing \"%s -d %s\": %s",
+               RESOLVCONF, ifname, strerror (errno));
       exit (0);
     }
   else if (pid == -1)
index 6c68d50e5807b67a9b3c3e5b1d2a668bda4559b7..1d55a09fc539f34b948c260e656d4afcd31d8d7e 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -30,7 +30,6 @@
 #include "common.h"
 
 #define DEFAULT_TIMEOUT                20
-// #define DEFAULT_LEASETIME   0xffffffff      /* infinite lease time */
 #define DEFAULT_LEASETIME      3600            /* 1 hour */
 
 #define CLASS_ID_MAX_LEN       48
index a7f715d25604b3c4e739a89d0053c2e333a630a1..a8bbf05d5b9fb83edb30dced3d3d3ddf86368f28 100644 (file)
@@ -211,7 +211,7 @@ interface_t *read_interface (const char *ifname, int metric)
   return iface;
 }
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
 static int do_address (const char *ifname, struct in_addr address,
                       struct in_addr netmask, struct in_addr broadcast, int del)
 {
index 0f7e0ef4eec3a6123fa98f48583c9f2e9ba8df30..2ef7a374d8b7dbfc0b14a1e39adaf1da6fdcab1a 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -49,9 +49,9 @@
 
 static uint16_t checksum (unsigned char *addr, uint16_t len)
 {
-  register uint32_t sum = 0;
-  register uint16_t *w = (uint16_t *) addr;
-  register uint16_t nleft = len;
+  uint32_t sum = 0;
+  uint16_t *w = (uint16_t *) addr;
+  uint16_t nleft = len;
 
   while (nleft > 1)
     {
@@ -159,7 +159,7 @@ eexit:
   return retval;
 }
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
 
 /* Credit where credit is due :)
    The below BPF filter is taken from ISC DHCP */