Better error handling on CLI initialization.
[l2tpns.git] / cli.c
diff --git a/cli.c b/cli.c
index 9433106..3a037fa 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -286,11 +286,19 @@ void init_cli(char *hostname)
        addr.sin_addr.s_addr = config->cli_bind_address; /* defaults to INADDR_ANY */
        addr.sin_port = htons(23);
        if (bind(clifd, (void *) &addr, sizeof(addr)) < 0)
+       {
+               LOG(0, 0, 0, "Error binding cli on port 23: %s\n", strerror(errno));
+               close(clifd);
+               clifd = -1;
+               return;
+       }
+       if (listen(clifd, 10) < 0)
        {
                LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno));
+               close(clifd);
+               clifd = -1;
                return;
        }
-       listen(clifd, 10);
 }
 
 void cli_do(int sockfd)