#ifndef __linux__
#include <pcap.h>
+
+/* Old versions of PCAP defined it as D_IN */
+#ifndef PCAP_D_IN
+#define PCAP_D_IN D_IN
+#endif
+
#endif
#include <avahi-common/malloc.h>
#include "main.h"
#include "iface.h"
+
+
/* An implementation of RFC 3927 */
/* Constants from the RFC */
#endif
static int no_drop_root = 0;
static int wrote_pid_file = 0;
+static char *action_script = NULL;
static enum {
DAEMON_RUN,
static int save_address(const char *fn, uint32_t addr) {
FILE *f;
char buf[32];
+ mode_t u;
assert(fn);
-
+
+ u = umask(0033);
if (!(f = fopen(fn, "w"))) {
daemon_log(LOG_ERR, "fopen() failed: %s", strerror(errno));
goto fail;
}
+ umask(u);
fprintf(f, "%s\n", inet_ntop(AF_INET, &addr, buf, sizeof (buf)));
fclose(f);
if (f)
fclose(f);
+ umask(u);
+
return -1;
}
sa.sll_halen = ETHER_ADDRLEN;
memset(sa.sll_addr, 0xFF, ETHER_ADDRLEN);
- if (sendto(fd, packet, packet_len, 0, (struct sockaddr*) &sa, sizeof(sa)) < 0) {
+ if (sendto(fd, packet->ether_payload, packet_len, 0, (struct sockaddr*) &sa, sizeof(sa)) < 0) {
daemon_log(LOG_ERR, "sendto() failed: %s", strerror(errno));
return -1;
}
((ntohl(addr) & 0x0000FF00) != 0xFF00);
}
-
static struct timeval *elapse_time(struct timeval *tv, unsigned msec, unsigned jitter) {
assert(tv);
}
if (daemon_exec("/", &k,
- AVAHI_IPCONF_SCRIPT, AVAHI_IPCONF_SCRIPT,
+ action_script, action_script,
callout_event_table[info.event],
name,
inet_ntop(AF_INET, &info.address, buf, sizeof(buf)), NULL) < 0) {
#elif defined(HAVE_SETREGID)
r = setregid(gr->gr_gid, gr->gr_gid);
#else
-#error "No API to drop priviliges"
+#error "No API to drop privileges"
#endif
if (r < 0) {
#elif defined(HAVE_SETREUID)
r = setreuid(pw->pw_uid, pw->pw_uid);
#else
-#error "No API to drop priviliges"
+#error "No API to drop privileges"
#endif
if (r < 0) {
daemon_log(LOG_INFO, "Successfully dropped root privileges.");
}
-
+
return 0;
}
FD_ARP,
FD_IFACE,
FD_SIGNAL,
- FD_MAX,
+ FD_MAX
};
int fd = -1, ret = -1;
if (info.sender_ip_address == addr) {
/* Normal conflict */
conflict = 1;
- daemon_log(LOG_INFO, "Recieved conflicting normal ARP packet.");
+ daemon_log(LOG_INFO, "Received conflicting normal ARP packet.");
} else if (state == STATE_WAITING_PROBE || state == STATE_PROBING || state == STATE_WAITING_ANNOUNCE) {
/* Probe conflict */
conflict = info.target_ip_address == addr && memcmp(hw_address, info.sender_hw_address, ETHER_ADDRLEN);
if (conflict)
- daemon_log(LOG_INFO, "Recieved conflicting probe ARP packet.");
+ daemon_log(LOG_INFO, "Received conflicting probe ARP packet.");
}
if (conflict) {
" -D --daemonize Daemonize after startup\n"
" -s --syslog Write log messages to syslog(3) instead of STDERR\n"
" -k --kill Kill a running daemon\n"
- " -r --refresh Request a running daemon to refresh it's IP address\n"
+ " -r --refresh Request a running daemon refresh its IP address\n"
" -c --check Return 0 if a daemon is already running\n"
" -V --version Show version\n"
" -S --start=ADDRESS Start with this address from the IPv4LL range\n"
" 169.254.0.0/16\n"
+ " -t --script=script Action script to run (defaults to\n"
+ " "AVAHI_IPCONF_SCRIPT")\n"
" -w --wait Wait until an address has been acquired before\n"
" daemonizing\n"
" --force-bind Assign an IPv4LL address even if a routable address\n"
{ "check", no_argument, NULL, 'c' },
{ "version", no_argument, NULL, 'V' },
{ "start", required_argument, NULL, 'S' },
+ { "script", required_argument, NULL, 't' },
{ "wait", no_argument, NULL, 'w' },
{ "force-bind", no_argument, NULL, OPTION_FORCE_BIND },
{ "no-drop-root", no_argument, NULL, OPTION_NO_DROP_ROOT },
{ NULL, 0, NULL, 0 }
};
- while ((c = getopt_long(argc, argv, "hDskrcVS:w", long_options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hDskrcVS:t:w", long_options, NULL)) >= 0) {
switch(c) {
case 's':
return -1;
}
break;
+ case 't':
+ avahi_free(action_script);
+ action_script = avahi_strdup(optarg);
+ break;
case 'w':
wait_for_address = 1;
break;
fprintf(stderr, "Too many arguments\n");
return -1;
}
+
+ if (!action_script)
+ action_script = avahi_strdup(AVAHI_IPCONF_SCRIPT);
return 0;
}
avahi_free(pid_file_name);
avahi_free(argv0);
avahi_free(interface_name);
+ avahi_free(action_script);
return r;
}