Changeset 3495654 in mainline for uspace/app/ping/ping.c
- Timestamp:
- 2013-04-30T19:28:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c7ba2d
- Parents:
- 9e7898e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ping/ping.c
r9e7898e r3495654 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 37 37 #include <errno.h> 38 38 #include <fibril_synch.h> 39 #include <inet/addr.h> 39 40 #include <inet/inetping.h> 40 41 #include <io/console.h> … … 71 72 } 72 73 73 static int addr_parse(const char *text, inet_addr_t *addr)74 {75 unsigned long a[4];76 char *cp = (char *)text;77 int i;78 79 for (i = 0; i < 3; i++) {80 a[i] = strtoul(cp, &cp, 10);81 if (*cp != '.')82 return EINVAL;83 ++cp;84 }85 86 a[3] = strtoul(cp, &cp, 10);87 if (*cp != '\0')88 return EINVAL;89 90 addr->ipv4 = 0;91 for (i = 0; i < 4; i++) {92 if (a[i] > 255)93 return EINVAL;94 addr->ipv4 = (addr->ipv4 << 8) | a[i];95 }96 97 return EOK;98 }99 100 static int addr_format(inet_addr_t *addr, char **bufp)101 {102 int rc;103 104 rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,105 (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,106 addr->ipv4 & 0xff);107 108 if (rc < 0)109 return ENOMEM;110 111 return EOK;112 }113 114 74 static void ping_signal_done(void) 115 75 { … … 125 85 int rc; 126 86 127 rc = addr_format(&sdu->src, &asrc);87 rc = inet_addr_format(&sdu->src, &asrc); 128 88 if (rc != EOK) 129 89 return ENOMEM; 130 90 131 rc = addr_format(&sdu->dest, &adest);91 rc = inet_addr_format(&sdu->dest, &adest); 132 92 if (rc != EOK) { 133 93 free(asrc); … … 237 197 238 198 /* Parse destination address */ 239 rc = addr_parse(argv[argi], &dest_addr);199 rc = inet_addr_parse(argv[argi], &dest_addr); 240 200 if (rc != EOK) { 241 201 printf(NAME ": Invalid address format.\n");
Note:
See TracChangeset
for help on using the changeset viewer.