Changes in uspace/app/ping/ping.c [959d2ec:3495654] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ping/ping.c
r959d2ec r3495654 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/dnsr.h>40 39 #include <inet/addr.h> 41 40 #include <inet/inetping.h> … … 70 69 static void print_syntax(void) 71 70 { 72 printf("syntax: " NAME " [-r] < host>\n");71 printf("syntax: " NAME " [-r] <addr>\n"); 73 72 } 74 73 … … 174 173 int main(int argc, char *argv[]) 175 174 { 176 dnsr_hostinfo_t *hinfo = NULL;177 char *asrc = NULL;178 char *adest = NULL;179 char *sdest = NULL;180 175 int rc; 181 176 int argi; … … 185 180 printf(NAME ": Failed connecting to internet ping service " 186 181 "(%d).\n", rc); 187 goto error;182 return 1; 188 183 } 189 184 … … 198 193 if (argc - argi != 1) { 199 194 print_syntax(); 200 goto error;195 return 1; 201 196 } 202 197 … … 204 199 rc = inet_addr_parse(argv[argi], &dest_addr); 205 200 if (rc != EOK) { 206 /* Try interpreting as a host name */ 207 rc = dnsr_name2host(argv[argi], &hinfo); 208 if (rc != EOK) { 209 printf(NAME ": Error resolving host '%s'.\n", argv[argi]); 210 goto error; 211 } 212 213 dest_addr = hinfo->addr; 201 printf(NAME ": Invalid address format.\n"); 202 print_syntax(); 203 return 1; 214 204 } 215 205 … … 218 208 if (rc != EOK) { 219 209 printf(NAME ": Failed determining source address.\n"); 220 goto error; 221 } 222 223 rc = inet_addr_format(&src_addr, &asrc); 224 if (rc != EOK) { 225 printf(NAME ": Out of memory.\n"); 226 goto error; 227 } 228 229 rc = inet_addr_format(&dest_addr, &adest); 230 if (rc != EOK) { 231 printf(NAME ": Out of memory.\n"); 232 goto error; 233 } 234 235 if (hinfo != NULL) { 236 rc = asprintf(&sdest, "%s (%s)", hinfo->cname, adest); 237 if (rc < 0) { 238 printf(NAME ": Out of memory.\n"); 239 goto error; 240 } 241 } else { 242 sdest = adest; 243 adest = NULL; 244 } 245 246 printf("Sending ICMP echo request from %s to %s.\n", 247 asrc, sdest); 210 return 1; 211 } 248 212 249 213 fid_t fid; … … 253 217 if (fid == 0) { 254 218 printf(NAME ": Failed creating transmit fibril.\n"); 255 goto error;219 return 1; 256 220 } 257 221 … … 261 225 if (fid == 0) { 262 226 printf(NAME ": Failed creating input fibril.\n"); 263 goto error;227 return 1; 264 228 } 265 229 … … 279 243 if (rc == ETIMEOUT) { 280 244 printf(NAME ": Echo request timed out.\n"); 281 goto error; 282 } 283 284 free(asrc); 285 free(adest); 286 free(sdest); 287 dnsr_hostinfo_destroy(hinfo); 245 return 1; 246 } 247 288 248 return 0; 289 error:290 free(asrc);291 free(adest);292 free(sdest);293 dnsr_hostinfo_destroy(hinfo);294 return 1;295 249 } 296 250
Note:
See TracChangeset
for help on using the changeset viewer.