DB *dbase;
char *dbname = "/var/lib/arpd/arpd.db";
-int ifnum;
+int ifnum;
int *ifvec;
char **ifnames;
};
#define IS_NEG(x) (((__u8*)(x))[0] == 0xFF)
-#define NEG_TIME(x) (((x)[2]<<24)|((x)[3]<<16)|((x)[4]<<8)|(x)[5])
+#define NEG_TIME(x) (((x)[2]<<24)|((x)[3]<<16)|((x)[4]<<8)|(x)[5])
#define NEG_AGE(x) ((__u32)time(NULL) - NEG_TIME((__u8*)x))
#define NEG_VALID(x) (NEG_AGE(x) < negative_timeout)
#define NEG_CNT(x) (((__u8*)(x))[1])
int no_kernel_broadcasts;
int broadcast_rate = 1000;
int broadcast_burst = 3000;
+int poll_timeout = 30000;
void usage(void)
{
fprintf(stderr,
-"Usage: arpd [ -lk ] [ -a N ] [ -b dbase ] [ -f file ] [ interfaces ]\n");
+ "Usage: arpd [ -lkh? ] [ -a N ] [ -b dbase ] [ -B number ]"
+ " [ -f file ] [ -n time ] [-p interval ] [ -R rate ] [ interfaces ]\n");
exit(1);
}
addattr_l(&req.n, sizeof(req), NDA_DST, &addr, 4);
addattr_l(&req.n, sizeof(req), NDA_LLADDR, lla, llalen);
- return rtnl_send(&rth, (char*)&req, req.n.nlmsg_len) <= 0;
+ return rtnl_send(&rth, &req, req.n.nlmsg_len) <= 0;
}
void prepare_neg_entry(__u8 *ndata, __u32 stamp)
DBT dbkey, dbdat;
int n;
- n = recvfrom(pset[0].fd, buf, sizeof(buf), MSG_DONTWAIT,
+ n = recvfrom(pset[0].fd, buf, sizeof(buf), MSG_DONTWAIT,
(struct sockaddr*)&sll, &sll_len);
if (n < 0) {
if (errno != EINTR && errno != EAGAIN)
key.iface = sll.sll_ifindex;
memcpy(&key.addr, (char*)(a+1) + a->ar_hln, 4);
- /* DAD message, ignore. */
+ /* DAD message, ignore. */
if (key.addr == 0)
return;
sa.sa_handler = handler;
#ifdef SA_INTERRUPT
sa.sa_flags = SA_INTERRUPT;
-#endif
+#endif
sigaction(sig, &sa, NULL);
}
int do_list = 0;
char *do_load = NULL;
- while ((opt = getopt(argc, argv, "h?b:lf:a:n:kR:B:")) != EOF) {
+ while ((opt = getopt(argc, argv, "h?b:lf:a:n:p:kR:B:")) != EOF) {
switch (opt) {
case 'b':
dbname = optarg;
case 'k':
no_kernel_broadcasts = 1;
break;
+ case 'p':
+ if ((poll_timeout = 1000 * strtod(optarg, NULL)) < 100) {
+ fprintf(stderr,"Invalid poll timeout\n");
+ exit(-1);
+ }
+ break;
case 'R':
if ((broadcast_rate = atoi(optarg)) <= 0 ||
(broadcast_rate = 1000/broadcast_rate) <= 0) {
DBT dbkey, dbdat;
printf("%-8s %-15s %s\n", "#Ifindex", "IP", "MAC");
while (dbase->seq(dbase, &dbkey, &dbdat, R_NEXT) == 0) {
- struct dbkey *key = dbkey.data;
+ struct dbkey *key = dbkey.data;
if (handle_if(key->iface)) {
if (!IS_NEG(dbdat.data)) {
char b1[18];
load_initial_table();
- if (1) {
- int fd;
- pid_t pid = fork();
-
- if (pid > 0)
- _exit(0);
- if (pid < 0) {
- perror("arpd: fork");
- goto do_abort;
- }
-
- chdir("/");
- fd = open("/dev/null", O_RDWR);
- if (fd >= 0) {
- dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
- if (fd > 2)
- close(fd);
- }
- setsid();
+ if (daemon(0, 0)) {
+ perror("arpd: daemon");
+ goto do_abort;
}
openlog("arpd", LOG_PID | LOG_CONS, LOG_DAEMON);
}
if (do_stats)
send_stats();
- if (poll(pset, 2, 30000) > 0) {
+ if (poll(pset, 2, poll_timeout) > 0) {
in_poll = 0;
if (pset[0].revents&EVENTS)
get_arp_pkt();