Ignore:
File:
1 edited

Legend:

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

    r26de91a r9d58539  
    3737#include <async.h>
    3838#include <stdio.h>
    39 #include <stdlib.h>
    4039#include <str.h>
    4140
    42 #include <inet/dnsr.h>
    4341#include <net/in.h>
    4442#include <net/in6.h>
     
    5351static char buf[BUF_SIZE];
    5452
    55 static struct sockaddr *address;
    56 static socklen_t addrlen;
     53static struct sockaddr_in addr;
    5754
    5855static uint16_t port;
     
    6360        int fd;
    6461        char *endptr;
    65         dnsr_hostinfo_t *hinfo;
    66         inet_addr_t addr;
    67         char *addr_s;
    6862
    6963        port = 7;
    7064
    71         data = (char *) "Hello World!";
     65        data = (char *)"Hello World!";
    7266        size = str_size(data);
    7367
    7468        /* Connect to local IP address by default */
    75         inet_addr(&addr, 127, 0, 0, 1);
     69        addr.sin_family = AF_INET;
     70        addr.sin_port = htons(port);
     71        addr.sin_addr.s_addr = htonl(0x7f000001);
    7672
    7773        if (argc >= 2) {
    7874                printf("parsing address '%s'\n", argv[1]);
    79                 rc = inet_addr_parse(argv[1], &addr);
     75                rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr);
    8076                if (rc != EOK) {
    81                         /* Try interpreting as a host name */
    82                         rc = dnsr_name2host(argv[1], &hinfo, ip_v4);
    83                         if (rc != EOK) {
    84                                 printf("Error resolving host '%s'.\n", argv[1]);
    85                                 return rc;
    86                         }
    87 
    88                         addr = hinfo->addr;
     77                        fprintf(stderr, "Error parsing address\n");
     78                        return 1;
    8979                }
    90                 rc = inet_addr_format(&addr, &addr_s);
    91                 if (rc != EOK) {
    92                         assert(rc == ENOMEM);
    93                         printf("Out of memory.\n");
    94                         return rc;
    95                 }
    96                 printf("result: rc=%d, ver=%d, addr=%s\n", rc,
    97                     addr.version, addr_s);
    98                 free(addr_s);
     80                printf("result: rc=%d, family=%d, addr=%x\n", rc,
     81                    addr.sin_family, addr.sin_addr.s_addr);
    9982        }
    10083
    10184        if (argc >= 3) {
    10285                printf("parsing port '%s'\n", argv[2]);
    103                 port = htons(strtoul(argv[2], &endptr, 10));
     86                addr.sin_port = htons(strtoul(argv[2], &endptr, 10));
    10487                if (*endptr != '\0') {
    10588                        fprintf(stderr, "Error parsing port\n");
     
    10891        }
    10992
    110         rc = inet_addr_sockaddr(&hinfo->addr, port, &address, &addrlen);
    111         if (rc != EOK) {
    112                 printf("Out of memory.\n");
    113                 return rc;
    114         }
    115 
    11693        printf("socket()\n");
    117         fd = socket(address->sa_family, SOCK_STREAM, IPPROTO_TCP);
     94        fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    11895        printf(" -> %d\n", fd);
    11996        if (fd < 0)
     
    12198
    12299        printf("connect()\n");
    123         rc = connect(fd, address, addrlen);
     100        rc = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
    124101        printf(" -> %d\n", rc);
    125102        if (rc != 0)
     
    138115        } while (rc > 0);
    139116
    140         async_usleep(1000 * 1000);
     117        async_usleep(1000*1000);
    141118
    142119        printf("closesocket()\n");
     
    144121        printf(" -> %d\n", rc);
    145122
    146         free(address);
    147 
    148123        return 0;
    149124}
    150125
     126
    151127/** @}
    152128 */
Note: See TracChangeset for help on using the changeset viewer.