2 * Copyright (c) 2013 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup dnscfg
32 /** @file DNS configuration utility.
34 * Controls the DNS resolution server (@c dnsrsrv).
38 #include <inet/addr.h>
39 #include <inet/dnsr.h>
40 #include <ipc/services.h>
45 #include <str_error.h>
49 static void print_syntax(void)
52 printf("\t%s get-ns\n", NAME
);
53 printf("\t%s set-ns <server-addr>\n", NAME
);
54 printf("\t%s unset-ns\n", NAME
);
57 static errno_t
dnscfg_set_ns(int argc
, char *argv
[])
60 printf("%s: Missing arguments.\n", NAME
);
66 printf("%s: Too many arguments.\n", NAME
);
71 char *srv_addr
= argv
[0];
74 errno_t rc
= inet_addr_parse(srv_addr
, &addr
, NULL
);
77 printf("%s: Invalid address format '%s'.\n", NAME
, srv_addr
);
81 rc
= dnsr_set_srvaddr(&addr
);
83 printf("%s: Failed setting nameserver address '%s' (%s)\n",
84 NAME
, srv_addr
, str_error(rc
));
91 static errno_t
dnscfg_unset_ns(void)
96 errno_t rc
= dnsr_set_srvaddr(&addr
);
98 printf("%s: Failed unsetting server address (%s)\n",
106 static errno_t
dnscfg_print(void)
109 errno_t rc
= dnsr_get_srvaddr(&addr
);
111 printf("%s: Failed getting DNS server address.\n", NAME
);
116 rc
= inet_addr_format(&addr
, &addr_str
);
118 printf("%s: Out of memory.\n", NAME
);
122 printf("Nameserver: %s\n", addr_str
);
127 int main(int argc
, char *argv
[])
129 if ((argc
< 2) || (str_cmp(argv
[1], "get-ns") == 0))
130 return dnscfg_print();
131 else if (str_cmp(argv
[1], "set-ns") == 0)
132 return dnscfg_set_ns(argc
- 2, argv
+ 2);
133 else if (str_cmp(argv
[1], "unset-ns") == 0)
134 return dnscfg_unset_ns();
136 printf("%s: Unknown command '%s'.\n", NAME
, argv
[1]);