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