Changeset 98abd40 in mainline for uspace/app/dnscfg/dnscfg.c
- Timestamp:
- 2013-07-06T21:57:22Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c8bb1633, cdc8a391
- Parents:
- b8e72fd1 (diff), 507c6f3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dnscfg/dnscfg.c
rb8e72fd1 r98abd40 49 49 static void print_syntax(void) 50 50 { 51 printf("syntax:\n"); 52 printf("\t" NAME " set-ns <server-addr>\n"); 53 printf("\t" NAME " unset-ns\n"); 51 printf("Syntax:\n"); 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); 54 55 } 55 56 56 57 static int dnscfg_set_ns(int argc, char *argv[]) 57 58 { 58 char *srv_addr;59 inet_addr_t addr;60 int rc;61 62 59 if (argc < 1) { 63 printf( NAME ": Missing arguments.\n");60 printf("%s: Missing arguments.\n", NAME); 64 61 print_syntax(); 65 62 return EINVAL; 66 63 } 67 64 68 65 if (argc > 1) { 69 printf( NAME ": Too many arguments.\n");66 printf("%s: Too many arguments.\n", NAME); 70 67 print_syntax(); 71 68 return EINVAL; 72 69 } 73 74 srv_addr = argv[0]; 75 76 rc = inet_addr_parse(srv_addr, &addr); 70 71 char *srv_addr = argv[0]; 72 73 inet_addr_t addr; 74 int rc = inet_addr_parse(srv_addr, &addr); 75 77 76 if (rc != EOK) { 78 printf( NAME ": Invalid address format '%s'.\n", srv_addr);79 return EINVAL;77 printf("%s: Invalid address format '%s'.\n", NAME, srv_addr); 78 return rc; 80 79 } 81 80 82 81 rc = dnsr_set_srvaddr(&addr); 83 82 if (rc != EOK) { 84 printf( NAME ": Failed settingserver address '%s' (%s)\n",85 srv_addr, str_error(rc));86 return EIO;83 printf("%s: Failed setting nameserver address '%s' (%s)\n", 84 NAME, srv_addr, str_error(rc)); 85 return rc; 87 86 } 88 87 89 88 return EOK; 90 89 } 91 90 92 static int dnscfg_unset_ns( int argc, char *argv[])91 static int dnscfg_unset_ns(void) 93 92 { 94 93 inet_addr_t addr; 95 int rc; 96 97 if (argc > 0) { 98 printf(NAME ": Too many arguments.\n"); 99 print_syntax(); 100 return EINVAL; 94 inet_addr_any(&addr); 95 96 int rc = dnsr_set_srvaddr(&addr); 97 if (rc != EOK) { 98 printf("%s: Failed unsetting server address (%s)\n", 99 NAME, str_error(rc)); 100 return rc; 101 101 } 102 103 addr.ipv4 = 0; 104 rc = dnsr_set_srvaddr(&addr); 105 if (rc != EOK) { 106 printf(NAME ": Failed unsetting server address (%s)\n", 107 str_error(rc)); 108 return EIO; 109 } 110 102 111 103 return EOK; 112 104 } … … 115 107 { 116 108 inet_addr_t addr; 117 char *addr_str; 118 int rc; 119 120 rc = dnsr_get_srvaddr(&addr); 109 int rc = dnsr_get_srvaddr(&addr); 121 110 if (rc != EOK) { 122 printf( NAME ": Failed getting DNS server address.\n");111 printf("%s: Failed getting DNS server address.\n", NAME); 123 112 return rc; 124 113 } 125 114 115 char *addr_str; 126 116 rc = inet_addr_format(&addr, &addr_str); 127 117 if (rc != EOK) { 128 printf( NAME ": Out of memory.\n");118 printf("%s: Out of memory.\n", NAME); 129 119 return rc; 130 120 } 131 132 printf(" Server: %s\n", addr_str);121 122 printf("Nameserver: %s\n", addr_str); 133 123 free(addr_str); 134 124 return EOK; … … 137 127 int main(int argc, char *argv[]) 138 128 { 139 int rc; 140 141 if (argc < 2) { 142 rc = dnscfg_print(); 143 if (rc != EOK) 144 return 1; 145 return 0; 146 } 147 148 if (str_cmp(argv[1], "set-ns") == 0) { 149 rc = dnscfg_set_ns(argc - 2, argv + 2); 150 if (rc != EOK) 151 return 1; 152 } else if (str_cmp(argv[1], "unset-ns") == 0) { 153 rc = dnscfg_unset_ns(argc - 2, argv + 2); 154 if (rc != EOK) 155 return 1; 156 } else { 157 printf(NAME ": Unknown command '%s'.\n", argv[1]); 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(); 135 else { 136 printf("%s: Unknown command '%s'.\n", NAME, argv[1]); 158 137 print_syntax(); 159 138 return 1; 160 139 } 161 162 140 163 141 return 0; 164 142 }
Note:
See TracChangeset
for help on using the changeset viewer.