Changeset 8fdb18e in mainline for uspace/app/ping/ping.c
- Timestamp:
- 2013-05-03T14:51:30Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5d1cb8a
- Parents:
- ef904895 (diff), 1c7ba2d (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
ref904895 r8fdb18e 38 38 #include <fibril_synch.h> 39 39 #include <inet/dnsr.h> 40 #include <inet/addr.h> 40 41 #include <inet/inetping.h> 41 42 #include <io/console.h> … … 72 73 } 73 74 74 static int addr_parse(const char *text, inet_addr_t *addr)75 {76 unsigned long a[4];77 char *cp = (char *)text;78 int i;79 80 for (i = 0; i < 3; i++) {81 a[i] = strtoul(cp, &cp, 10);82 if (*cp != '.')83 return EINVAL;84 ++cp;85 }86 87 a[3] = strtoul(cp, &cp, 10);88 if (*cp != '\0')89 return EINVAL;90 91 addr->ipv4 = 0;92 for (i = 0; i < 4; i++) {93 if (a[i] > 255)94 return EINVAL;95 addr->ipv4 = (addr->ipv4 << 8) | a[i];96 }97 98 return EOK;99 }100 101 static int addr_format(inet_addr_t *addr, char **bufp)102 {103 int rc;104 105 rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,106 (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,107 addr->ipv4 & 0xff);108 109 if (rc < 0)110 return ENOMEM;111 112 return EOK;113 }114 115 75 static void ping_signal_done(void) 116 76 { … … 126 86 int rc; 127 87 128 rc = addr_format(&sdu->src, &asrc);88 rc = inet_addr_format(&sdu->src, &asrc); 129 89 if (rc != EOK) 130 90 return ENOMEM; 131 91 132 rc = addr_format(&sdu->dest, &adest);92 rc = inet_addr_format(&sdu->dest, &adest); 133 93 if (rc != EOK) { 134 94 free(asrc); … … 242 202 243 203 /* Parse destination address */ 244 rc = addr_parse(argv[argi], &dest_addr);204 rc = inet_addr_parse(argv[argi], &dest_addr); 245 205 if (rc != EOK) { 246 206 /* Try interpreting as a host name */ … … 261 221 } 262 222 263 rc = addr_format(&src_addr, &asrc);223 rc = inet_addr_format(&src_addr, &asrc); 264 224 if (rc != EOK) { 265 225 printf(NAME ": Out of memory.\n"); … … 267 227 } 268 228 269 rc = addr_format(&dest_addr, &adest);229 rc = inet_addr_format(&dest_addr, &adest); 270 230 if (rc != EOK) { 271 231 printf(NAME ": Out of memory.\n");
Note:
See TracChangeset
for help on using the changeset viewer.