diff options
author | Simon Kelley <simon@thekelleys.org.uk> | 2006-05-06 14:13:33 +0100 |
---|---|---|
committer | Simon Kelley <simon@thekelleys.org.uk> | 2012-01-05 17:31:12 +0000 |
commit | 7cebd20fe7671ba108625b8d863293da7ca40b09 (patch) | |
tree | e28000e0a8a22ae77d285561facbc23a8ed6a38c /src/netlink.c | |
parent | 26d0dbaf2496cfba2abd837fca8b783608b1eadc (diff) | |
download | dnsmasq-7cebd20fe7671ba108625b8d863293da7ca40b09.tar.gz |
import of dnsmasq-2.31.tar.gzv2.31
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 53 |
1 files changed, 10 insertions, 43 deletions
diff --git a/src/netlink.c b/src/netlink.c index a396bb2..1be6c9a 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -48,8 +48,14 @@ void netlink_init(struct daemon *daemon) } if (daemon->netlinkfd == -1) - die(_("cannot create RTnetlink socket: %s"), NULL); - + die(_("cannot create netlink socket: %s"), NULL); + else + { + int flags = fcntl(daemon->netlinkfd, F_GETFD); + if (flags != -1) + fcntl(daemon->netlinkfd, F_SETFD, flags | FD_CLOEXEC); + } + iov.iov_len = 200; iov.iov_base = safe_malloc(iov.iov_len); } @@ -114,7 +120,7 @@ int iface_enumerate(struct daemon *daemon, void *parm, int (*ipv4_callback)(), i again: req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = RTM_GETADDR; - req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST; + req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST | NLM_F_ACK; req.nlh.nlmsg_pid = 0; req.nlh.nlmsg_seq = ++seq; req.g.rtgen_family = family; @@ -215,7 +221,7 @@ static void nl_err(struct nlmsghdr *h) { struct nlmsgerr *err = NLMSG_DATA(h); if (err->error != 0) - syslog(LOG_ERR, _("RTnetlink returns error: %s"), strerror(-(err->error))); + syslog(LOG_ERR, _("netlink returns error: %s"), strerror(-(err->error))); } /* We arrange to receive netlink multicast messages whenever the network route is added. @@ -234,45 +240,6 @@ static void nl_routechange(struct daemon *daemon, struct nlmsghdr *h) &daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send()); } } - -void arp_inject(int fd, struct in_addr ip_addr, int iface, - unsigned char *mac, unsigned int mac_len) -{ - struct sockaddr_nl addr; - struct { - struct nlmsghdr nlh; - struct ndmsg m; - struct rtattr addr_attr; - struct in_addr addr; - struct rtattr ll_attr; - char mac[DHCP_CHADDR_MAX]; - } req; - - memset(&req, 0, sizeof(req)); - memset(&addr, 0, sizeof(addr)); - - addr.nl_family = AF_NETLINK; - - req.nlh.nlmsg_len = sizeof(req); - req.nlh.nlmsg_type = RTM_NEWNEIGH; - req.nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_REPLACE | NLM_F_CREATE; - - req.m.ndm_family = AF_INET; - req.m.ndm_ifindex = iface; - req.m.ndm_state = NUD_REACHABLE; - - req.addr_attr.rta_type = NDA_DST; - req.addr_attr.rta_len = RTA_LENGTH(sizeof(struct in_addr)); - req.addr = ip_addr; - - req.ll_attr.rta_type = NDA_LLADDR; - req.ll_attr.rta_len = RTA_LENGTH(mac_len); - memcpy(req.mac, mac, mac_len); - - while(sendto(fd, (void *)&req, sizeof(req), 0, (struct sockaddr *)&addr, sizeof(addr)) == -1 && - retry_send()); -} - #endif |