}
}
- struct ifreq ifr = {.ifr_name = ""};
- strncpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name));
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name) - 1);
if (!ioctl(sock, SIOCGIFMTU, &ifr)) {
uint16_t mtu = htons(ifr.ifr_mtu);
int odhcpd_get_mac(const struct interface *iface, uint8_t mac[6])
{
struct ifreq ifr;
+
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name));
+ strncpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name) - 1);
if (ioctl(ioctl_sock, SIOCGIFHWADDR, &ifr) < 0)
return -1;
+
memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
return 0;
}