Changes in uspace/app/nettest3/nettest3.c [26de91a:fff7ef4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest3/nettest3.c
r26de91a rfff7ef4 37 37 #include <async.h> 38 38 #include <stdio.h> 39 #include <stdlib.h>40 39 #include <str.h> 41 40 … … 53 52 static char buf[BUF_SIZE]; 54 53 55 static struct sockaddr *address; 56 static socklen_t addrlen; 54 static struct sockaddr_in addr; 57 55 58 56 static uint16_t port; … … 64 62 char *endptr; 65 63 dnsr_hostinfo_t *hinfo; 66 inet_addr_t addr;67 char *addr_s;68 64 69 65 port = 7; … … 73 69 74 70 /* Connect to local IP address by default */ 75 inet_addr(&addr, 127, 0, 0, 1); 71 addr.sin_family = AF_INET; 72 addr.sin_port = htons(port); 73 addr.sin_addr.s_addr = htonl(0x7f000001); 76 74 77 75 if (argc >= 2) { 78 76 printf("parsing address '%s'\n", argv[1]); 79 rc = inet_ addr_parse(argv[1], &addr);77 rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr); 80 78 if (rc != EOK) { 81 79 /* Try interpreting as a host name */ 82 rc = dnsr_name2host(argv[1], &hinfo , ip_v4);80 rc = dnsr_name2host(argv[1], &hinfo); 83 81 if (rc != EOK) { 84 82 printf("Error resolving host '%s'.\n", argv[1]); … … 86 84 } 87 85 88 addr = hinfo->addr; 86 addr.sin_addr.s_addr = host2uint32_t_be(hinfo->addr.ipv4); 87 addr.sin_family = AF_INET; 89 88 } 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); 89 printf("result: rc=%d, family=%d, addr=%x\n", rc, 90 addr.sin_family, addr.sin_addr.s_addr); 99 91 } 100 92 101 93 if (argc >= 3) { 102 94 printf("parsing port '%s'\n", argv[2]); 103 port = htons(strtoul(argv[2], &endptr, 10));95 addr.sin_port = htons(strtoul(argv[2], &endptr, 10)); 104 96 if (*endptr != '\0') { 105 97 fprintf(stderr, "Error parsing port\n"); … … 108 100 } 109 101 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 116 102 printf("socket()\n"); 117 fd = socket( address->sa_family, SOCK_STREAM, IPPROTO_TCP);103 fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); 118 104 printf(" -> %d\n", fd); 119 105 if (fd < 0) … … 121 107 122 108 printf("connect()\n"); 123 rc = connect(fd, address, addrlen);109 rc = connect(fd, (struct sockaddr *) &addr, sizeof(addr)); 124 110 printf(" -> %d\n", rc); 125 111 if (rc != 0) … … 144 130 printf(" -> %d\n", rc); 145 131 146 free(address);147 148 132 return 0; 149 133 }
Note:
See TracChangeset
for help on using the changeset viewer.