dhcpv4: remove comment code lines
[project/odhcpd.git] / src / dhcpv4.c
index 462f641..0f613b2 100644 (file)
@@ -119,18 +119,11 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable)
                }
 
                // Create a range if not specified
-               struct ifreq ifreq;
-               strncpy(ifreq.ifr_name, iface->ifname, sizeof(ifreq.ifr_name));
-
-               struct sockaddr_in *saddr = (struct sockaddr_in*)&ifreq.ifr_addr;
-               struct sockaddr_in *smask = (struct sockaddr_in*)&ifreq.ifr_netmask;
                if (!(iface->dhcpv4_start.s_addr & htonl(0xffff0000)) &&
-                               !(iface->dhcpv4_end.s_addr & htonl(0xffff0000)) &&
-                               !ioctl(sock, SIOCGIFADDR, &ifreq)) {
-                       struct in_addr addr = saddr->sin_addr;
+                               !(iface->dhcpv4_end.s_addr & htonl(0xffff0000))) {
+                       struct in_addr addr = ubus_get_address4(iface->ifname);
 
-                       ioctl(sock, SIOCGIFNETMASK, &ifreq);
-                       struct in_addr mask = smask->sin_addr;
+                       struct in_addr mask = ubus_get_mask4(iface->ifname);
 
                        uint32_t start = ntohl(iface->dhcpv4_start.s_addr);
                        uint32_t end = ntohl(iface->dhcpv4_end.s_addr);
@@ -222,7 +215,6 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable)
                        struct dhcpv4_assignment *a = list_first_entry(&iface->dhcpv4_assignments,
                                        struct dhcpv4_assignment, head);
                        list_del(&a->head);
-                       free(a->hostname);
                        free(a);
                }
 
@@ -554,12 +546,12 @@ static bool dhcpv4_assign(struct interface *iface,
                return true;
        }
 
-       for (size_t i = 0; i < count; ++i) {
+       for (uint32_t i = 0; i < count; ++i) {
                if (dhcpv4_test(iface, try)) {
                        /* test was successful: IP address is not assigned, assign it */
                        assign->addr = try;
                        list_add(&assign->head, &iface->dhcpv4_assignments);
-                       syslog(LOG_DEBUG, "assigning mapped IP: %u.%u.%u.%u (try %d of %d)",
+                       syslog(LOG_DEBUG, "assigning mapped IP: %u.%u.%u.%u (try %u of %u)",
                                        (assign->addr & 0xff000000) >> 24,
                                        (assign->addr & 0x00ff0000) >> 16,
                                        (assign->addr & 0x0000ff00) >> 8,
@@ -637,7 +629,7 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
        } else if (msg == DHCPV4_MSG_RELEASE) {
                if (a && a->valid_until != LONG_MAX)
                        a->valid_until = 0;
-       } else if (msg == DHCPV4_MSG_DECLINE && a->valid_until != LONG_MAX) {
+       } else if (msg == DHCPV4_MSG_DECLINE && a && a->valid_until != LONG_MAX) {
                memset(a->hwaddr, 0, sizeof(a->hwaddr));
                a->valid_until = now + 3600; // Block address for 1h
        }