netutils/dhcpd: minor patch for handling exception cases
authorJin-Seong Kim <jseong82.kim@samsung.com>
Tue, 11 Apr 2017 04:47:39 +0000 (13:47 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Tue, 18 Apr 2017 03:02:16 +0000 (12:02 +0900)
This commit is the patch to handling exception cases
 - when abnormal interface name is coming from applications,
   dhcpd should not run
 - dhcpd_run always return OK, it is not good to handle operation
   of dhcpd in application

Change-Id: I88249dabd727fdd1f8af5a6749efc99ded56406f
Signed-off-by: Jin-Seong Kim <jseong82.kim@samsung.com>
apps/netutils/dhcpd/dhcpd.c

index 7fcfbe8..1205683 100755 (executable)
@@ -1538,7 +1538,7 @@ int dhcpd_run(void *arg)
        int sockfd;
        int nbytes;
 #if DHCPD_SELECT
-       int ret;
+       int ret = OK;
        fd_set sockfd_set;
 #endif
        ndbg("Started on %s\n", DHCPD_IFNAME);
@@ -1547,6 +1547,14 @@ int dhcpd_run(void *arg)
 
        memset(&g_state, 0, sizeof(struct dhcpd_state_s));
 
+       /* Initialize netif address (ip address, netmask, default gateway) */
+
+       if (dhcpd_netif_init(DHCPD_IFNAME) < 0) {
+               ndbg("Failed to initialize network interface %s\n", DHCPD_IFNAME);
+               ret = ERROR;
+               return ret;
+       }
+
        /* Now loop indefinitely, reading packets from the DHCP server socket */
 
        sockfd = -1;
@@ -1554,10 +1562,6 @@ int dhcpd_run(void *arg)
        g_dhcpd_quit = 0;
        g_dhcpd_running = 1;
 
-       /* Initialize netif address (ip address, netmask, default gateway) */
-
-       dhcpd_netif_init(DHCPD_IFNAME);
-
        while (!g_dhcpd_quit) {
                /* Create a socket to listen for requests from DHCP clients */
 
@@ -1567,6 +1571,7 @@ int dhcpd_run(void *arg)
                        sockfd = dhcpd_openlistener();
                        if (sockfd < 0) {
                                ndbg("Failed to create socket\n");
+                               ret = ERROR;
                                break;
                        }
                }
@@ -1660,7 +1665,7 @@ int dhcpd_run(void *arg)
 
        dhcpd_netif_deinit(DHCPD_IFNAME);
 
-       return OK;
+       return ret;
 }