ssize_t sent = sendmsg(socket, &msg, MSG_DONTWAIT);
if (sent < 0)
- syslog(LOG_NOTICE, "Failed to send to %s%%%s (%s)",
- ipbuf, iface->ifname, strerror(errno));
+ syslog(LOG_NOTICE, "Failed to send to %s%%%s (%m)",
+ ipbuf, iface->ifname);
else
syslog(LOG_DEBUG, "Sent %li bytes to %s%%%s",
(long)sent, ipbuf, iface->ifname);
if (addr.ll.sll_family == AF_PACKET)
destiface = addr.ll.sll_ifindex;
- struct interface *iface =
- odhcpd_get_interface_by_index(destiface);
-
- if (!iface && addr.nl.nl_family != AF_NETLINK)
- continue;
-
char ipbuf[INET6_ADDRSTRLEN] = "kernel";
if (addr.ll.sll_family == AF_PACKET &&
len >= (ssize_t)sizeof(struct ip6_hdr))
else if (addr.in.sin_family == AF_INET)
inet_ntop(AF_INET, &addr.in.sin_addr, ipbuf, sizeof(ipbuf));
- syslog(LOG_DEBUG, "Received %li Bytes from %s%%%s", (long)len,
- ipbuf, (iface) ? iface->ifname : "netlink");
+ // From netlink
+ if (addr.nl.nl_family == AF_NETLINK) {
+ syslog(LOG_DEBUG, "Received %li Bytes from %s%%%s", (long)len,
+ ipbuf, "netlink");
+ e->handle_dgram(&addr, data_buf, len, NULL, dest);
+ return;
+ } else if (destiface != 0) {
+ struct interface *iface;
+ list_for_each_entry(iface, &interfaces, head) {
+ if (iface->ifindex != destiface)
+ continue;
+
+ syslog(LOG_DEBUG, "Received %li Bytes from %s%%%s", (long)len,
+ ipbuf, iface->ifname);
+
+ e->handle_dgram(&addr, data_buf, len, iface, dest);
+ }
+ }
+
- e->handle_dgram(&addr, data_buf, len, iface, dest);
}
}
*dst = 0;
}
+const char *odhcpd_print_mac(const uint8_t *mac, const size_t len)
+{
+ static char buf[32];
+
+ snprintf(buf, sizeof(buf), "%02x", mac[0]);
+ for (size_t i = 1, j = 2; i < len && j < sizeof(buf); i++, j += 3)
+ snprintf(buf + j, sizeof(buf) - j, ":%02x", mac[i]);
+
+ return buf;
+}
int odhcpd_bmemcmp(const void *av, const void *bv, size_t bits)
{