Changeset 8fdb18e in mainline for uspace/app/ping/ping.c


Ignore:
Timestamp:
2013-05-03T14:51:30Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
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.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/ping/ping.c

    ref904895 r8fdb18e  
    3838#include <fibril_synch.h>
    3939#include <inet/dnsr.h>
     40#include <inet/addr.h>
    4041#include <inet/inetping.h>
    4142#include <io/console.h>
     
    7273}
    7374
    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 
    11575static void ping_signal_done(void)
    11676{
     
    12686        int rc;
    12787
    128         rc = addr_format(&sdu->src, &asrc);
     88        rc = inet_addr_format(&sdu->src, &asrc);
    12989        if (rc != EOK)
    13090                return ENOMEM;
    13191
    132         rc = addr_format(&sdu->dest, &adest);
     92        rc = inet_addr_format(&sdu->dest, &adest);
    13393        if (rc != EOK) {
    13494                free(asrc);
     
    242202
    243203        /* Parse destination address */
    244         rc = addr_parse(argv[argi], &dest_addr);
     204        rc = inet_addr_parse(argv[argi], &dest_addr);
    245205        if (rc != EOK) {
    246206                /* Try interpreting as a host name */
     
    261221        }
    262222
    263         rc = addr_format(&src_addr, &asrc);
     223        rc = inet_addr_format(&src_addr, &asrc);
    264224        if (rc != EOK) {
    265225                printf(NAME ": Out of memory.\n");
     
    267227        }
    268228
    269         rc = addr_format(&dest_addr, &adest);
     229        rc = inet_addr_format(&dest_addr, &adest);
    270230        if (rc != EOK) {
    271231                printf(NAME ": Out of memory.\n");
Note: See TracChangeset for help on using the changeset viewer.