Changeset 4e716180 in mainline for uspace/app/ping/ping.c
- Timestamp:
- 2013-05-03T21:14:39Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 716357f
- Parents:
- 1c7ba2d (diff), 5d1cb8a (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/ping/ping.c
r1c7ba2d r4e716180 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/dnsr.h> 39 40 #include <inet/addr.h> 40 41 #include <inet/inetping.h> … … 69 70 static void print_syntax(void) 70 71 { 71 printf("syntax: " NAME " [-r] < addr>\n");72 printf("syntax: " NAME " [-r] <host>\n"); 72 73 } 73 74 … … 173 174 int main(int argc, char *argv[]) 174 175 { 176 dnsr_hostinfo_t *hinfo = NULL; 177 char *asrc = NULL; 178 char *adest = NULL; 179 char *sdest = NULL; 175 180 int rc; 176 181 int argi; … … 180 185 printf(NAME ": Failed connecting to internet ping service " 181 186 "(%d).\n", rc); 182 return 1;187 goto error; 183 188 } 184 189 … … 193 198 if (argc - argi != 1) { 194 199 print_syntax(); 195 return 1;200 goto error; 196 201 } 197 202 … … 199 204 rc = inet_addr_parse(argv[argi], &dest_addr); 200 205 if (rc != EOK) { 201 printf(NAME ": Invalid address format.\n"); 202 print_syntax(); 203 return 1; 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; 204 214 } 205 215 … … 208 218 if (rc != EOK) { 209 219 printf(NAME ": Failed determining source address.\n"); 210 return 1; 211 } 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->name, 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); 212 248 213 249 fid_t fid; … … 217 253 if (fid == 0) { 218 254 printf(NAME ": Failed creating transmit fibril.\n"); 219 return 1;255 goto error; 220 256 } 221 257 … … 225 261 if (fid == 0) { 226 262 printf(NAME ": Failed creating input fibril.\n"); 227 return 1;263 goto error; 228 264 } 229 265 … … 243 279 if (rc == ETIMEOUT) { 244 280 printf(NAME ": Echo request timed out.\n"); 245 return 1; 246 } 247 281 goto error; 282 } 283 284 free(asrc); 285 free(adest); 286 free(sdest); 287 dnsr_hostinfo_destroy(hinfo); 248 288 return 0; 289 error: 290 free(asrc); 291 free(adest); 292 free(sdest); 293 dnsr_hostinfo_destroy(hinfo); 294 return 1; 249 295 } 250 296
Note:
See TracChangeset
for help on using the changeset viewer.