Changes in uspace/app/ping/ping.c [07b7c48:3495654] in mainline


Ignore:
File:
1 edited

Legend:

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

    r07b7c48 r3495654  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#include <errno.h>
    3838#include <fibril_synch.h>
     39#include <inet/addr.h>
    3940#include <inet/inetping.h>
    4041#include <io/console.h>
     
    7172}
    7273
    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 
    11474static void ping_signal_done(void)
    11575{
     
    12585        int rc;
    12686
    127         rc = addr_format(&sdu->src, &asrc);
     87        rc = inet_addr_format(&sdu->src, &asrc);
    12888        if (rc != EOK)
    12989                return ENOMEM;
    13090
    131         rc = addr_format(&sdu->dest, &adest);
     91        rc = inet_addr_format(&sdu->dest, &adest);
    13292        if (rc != EOK) {
    13393                free(asrc);
     
    237197
    238198        /* Parse destination address */
    239         rc = addr_parse(argv[argi], &dest_addr);
     199        rc = inet_addr_parse(argv[argi], &dest_addr);
    240200        if (rc != EOK) {
    241201                printf(NAME ": Invalid address format.\n");
Note: See TracChangeset for help on using the changeset viewer.