Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 453f9e33 in mainline


Ignore:
Timestamp:
2011-12-05T18:38:15Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
5f9ecd3
Parents:
bf600510
Message:

Allow specifying IP address and port on test3 command line.

File:
1 edited

Legend:

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

    rbf600510 r453f9e33  
    5959        int rc;
    6060        int fd;
     61        char *endptr;
    6162
    62         port = 80;
     63        port = 7;
    6364
    6465        data = (char *)"Hello World!";
    6566        size = str_size(data);
    6667
     68        /* Connect to local IP address by default */
    6769        addr.sin_family = AF_INET;
    6870        addr.sin_port = htons(port);
    6971        addr.sin_addr.s_addr = htonl(0x7f000001);
     72
     73        if (argc >= 2) {
     74                printf("parsing address '%s'\n", argv[1]);
     75                rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr);
     76                if (rc != EOK) {
     77                        fprintf(stderr, "Error parsing address\n");
     78                        return 1;
     79                }
     80                printf("result: rc=%d, family=%d, addr=%x\n", rc,
     81                    addr.sin_family, addr.sin_addr.s_addr);
     82        }
     83
     84        if (argc >= 3) {
     85                printf("parsing port '%s'\n", argv[2]);
     86                addr.sin_port = htons(strtoul(argv[2], &endptr, 10));
     87                if (*endptr != '\0') {
     88                        fprintf(stderr, "Error parsing port\n");
     89                        return 1;
     90                }
     91        }
    7092
    7193        printf("socket()\n");
Note: See TracChangeset for help on using the changeset viewer.