Changeset 9749e47 in mainline for uspace/app/ping/ping.c


Ignore:
Timestamp:
2013-10-04T19:23:43Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1d04b2
Parents:
26de91a
Message:

ping6 - resistance is futile.

File:
1 edited

Legend:

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

    r26de91a r9749e47  
    7676};
    7777
    78 static addr32_t src;
    79 static addr32_t dest;
     78static inet_addr_t src_addr;
     79static inet_addr_t dest_addr;
    8080
    8181static bool repeat_forever = false;
    8282static size_t repeat_count = 1;
    8383
    84 static const char *short_options = "rn:";
     84static const char *short_options = "46rn:";
    8585
    8686static void print_syntax(void)
    8787{
    88         printf("Syntax: %s [-n <count>|-r] <host>\n", NAME);
     88        printf("Syntax: %s [<options>] <host>\n", NAME);
     89        printf("\t-n <count> Repeat the specified number of times\n");
     90        printf("\t-r         Repeat forever\n");
     91        printf("\t-4|-6      Use IPv4 or IPv6 destination host address\n");
    8992}
    9093
     
    107110static int ping_ev_recv(inetping_sdu_t *sdu)
    108111{
    109         inet_addr_t src_addr;
    110         inet_addr_set(sdu->src, &src_addr);
    111        
    112         inet_addr_t dest_addr;
    113         inet_addr_set(sdu->dest, &dest_addr);
    114        
    115112        char *asrc;
    116113        int rc = inet_addr_format(&src_addr, &asrc);
     
    139136        inetping_sdu_t sdu;
    140137       
    141         sdu.src = src;
    142         sdu.dest = dest;
     138        sdu.src = src_addr;
     139        sdu.dest = dest_addr;
    143140        sdu.seq_no = seq_no;
    144141        sdu.data = (void *) "foo";
     
    221218        char *adest = NULL;
    222219        char *sdest = NULL;
     220        ip_ver_t ip_ver = ip_any;
    223221       
    224222        int rc = inetping_init(&ev_ops);
     
    243241                        }
    244242                        break;
     243                case '4':
     244                        ip_ver = ip_v4;
     245                        break;
     246                case '6':
     247                        ip_ver = ip_v6;
     248                        break;
    245249                default:
    246250                        printf("Unknown option passed.\n");
     
    257261       
    258262        /* Parse destination address */
    259         inet_addr_t dest_addr;
    260263        rc = inet_addr_parse(argv[optind], &dest_addr);
    261264        if (rc != EOK) {
    262265                /* Try interpreting as a host name */
    263                 rc = dnsr_name2host(argv[optind], &hinfo, ip_v4);
     266                rc = dnsr_name2host(argv[optind], &hinfo, ip_ver);
    264267                if (rc != EOK) {
    265268                        printf("Error resolving host '%s'.\n", argv[optind]);
     
    270273        }
    271274       
    272         ip_ver_t ver = inet_addr_get(&dest_addr, &dest, NULL);
    273         if (ver != ip_v4) {
    274                 printf("Destination '%s' is not an IPv4 address.\n",
    275                     argv[optind]);
    276                 goto error;
    277         }
    278        
    279275        /* Determine source address */
    280         rc = inetping_get_srcaddr(dest, &src);
     276        rc = inetping_get_srcaddr(&dest_addr, &src_addr);
    281277        if (rc != EOK) {
    282278                printf("Failed determining source address.\n");
    283279                goto error;
    284280        }
    285        
    286         inet_addr_t src_addr;
    287         inet_addr_set(src, &src_addr);
    288281       
    289282        rc = inet_addr_format(&src_addr, &asrc);
Note: See TracChangeset for help on using the changeset viewer.