From: Roy Marples Date: Fri, 15 Dec 2006 18:28:54 +0000 (+0000) Subject: dhcpcd is reported to work on Darwin :) X-Git-Tag: v3.2.3~340 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb9f54013c3df5b7013e628dd83ee658c287b63b;p=thirdparty%2Fdhcpcd.git dhcpcd is reported to work on Darwin :) --- diff --git a/ChangeLog b/ChangeLog index b9e77f96..09e8006e 100644 --- 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. diff --git a/Makefile b/Makefile index 95f17cbc..f9903590 100644 --- 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 diff --git a/common.c b/common.c index e1f5f513..5739e4ff 100644 --- 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 +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 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; diff --git a/configure.c b/configure.c index d86b8eba..e88bbfb9 100644 --- a/configure.c +++ b/configure.c @@ -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) diff --git a/dhcpcd.h b/dhcpcd.h index 6c68d50e..1d55a09f 100644 --- 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 diff --git a/interface.c b/interface.c index a7f715d2..a8bbf05d 100644 --- a/interface.c +++ b/interface.c @@ -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) { diff --git a/socket.c b/socket.c index 0f7e0ef4..2ef7a374 100644 --- 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 */