+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.
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
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)
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;
/* 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++ = '\\';
*b++ = '\'';
}
else
- *b++ = *c;
- while (*c++);
+ *b++ = *cstr;
+ while (*cstr++);
*b++ = 0;
b = buffer;
{
struct stat buf;
pid_t pid;
- char *const argc[4] =
- { (char *) script, (char *) infofile, (char *) arg, NULL };
if (! script || ! infofile || ! arg)
return;
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)
{
struct stat buf;
pid_t pid;
- char *const argc[4] =
- { (char *) RESOLVCONF, (char *) "-d", (char *) ifname, NULL };
if (stat (RESOLVCONF, &buf) < 0)
return;
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)
#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
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)
{
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)
{
return retval;
}
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__APPLE__)
/* Credit where credit is due :)
The below BPF filter is taken from ISC DHCP */