unet-cli: strip initial newline in usage message
[project/unetd.git] / main.c
diff --git a/main.c b/main.c
index f3b05d22d288aae2f1f240ac4db4bef6e6652c1e..be24db768ced14db1737f138a40856b1ef3e2127 100644 (file)
--- a/main.c
+++ b/main.c
@@ -18,6 +18,7 @@ static struct cmdline_network *cmd_nets;
 static const char *hosts_file;
 const char *mssfix_path = UNETD_MSS_BPF_PATH;
 const char *data_dir = UNETD_DATA_DIR;
+int global_pex_port = UNETD_GLOBAL_PEX_PORT;
 bool debug;
 
 static void
@@ -31,7 +32,9 @@ network_write_hosts(struct network *net, FILE *f)
 
        avl_for_each_element(&net->hosts, host, node) {
                inet_ntop(AF_INET6, &host->peer.local_addr, ip, sizeof(ip));
-               fprintf(f, "%s\t%s\n", ip, network_host_name(host));
+               fprintf(f, "%s\t%s%s%s\n", ip, network_host_name(host),
+                       net->config.domain ? "." : "",
+                       net->config.domain ? net->config.domain : "");
        }
 }
 
@@ -45,7 +48,9 @@ void unetd_write_hosts(void)
        if (!hosts_file)
                return;
 
-       asprintf(&tmpfile, "%s.XXXXXXXX", hosts_file);
+       if (asprintf(&tmpfile, "%s.XXXXXXXX", hosts_file) < 0)
+               return;
+
        fd = mkstemp(tmpfile);
        if (fd < 0) {
                perror("mkstemp");
@@ -96,9 +101,10 @@ static void add_networks(void)
 int main(int argc, char **argv)
 {
        struct cmdline_network *net;
+       const char *unix_socket = NULL;
        int ch;
 
-       while ((ch = getopt(argc, argv, "D:dh:M:N:")) != -1) {
+       while ((ch = getopt(argc, argv, "D:dh:u:M:N:P:")) != -1) {
                switch (ch) {
                case 'D':
                        data_dir = optarg;
@@ -118,14 +124,22 @@ int main(int argc, char **argv)
                case 'M':
                        mssfix_path = optarg;
                        break;
+               case 'P':
+                       global_pex_port = atoi(optarg);
+                       break;
+               case 'u':
+                       unix_socket = optarg;
+                       break;
                }
        }
 
        uloop_init();
        unetd_ubus_init();
        unetd_write_hosts();
+       global_pex_open(unix_socket);
        add_networks();
        uloop_run();
+       pex_close();
        network_free_all();
        uloop_done();