summaryrefslogtreecommitdiff
path: root/testing/Lossless_UDP_testclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r--testing/Lossless_UDP_testclient.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c
index d5fb1544..70349204 100644
--- a/testing/Lossless_UDP_testclient.c
+++ b/testing/Lossless_UDP_testclient.c
@@ -66,8 +66,7 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port)
66 66
67void printip(IP_Port ip_port) 67void printip(IP_Port ip_port)
68{ 68{
69 printf("\nIP: %u.%u.%u.%u Port: %u", ip_port.ip.uint8[0], ip_port.ip.uint8[1], ip_port.ip.uint8[2], ip_port.ip.uint8[3], 69 printf("\nIP: %s Port: %u", ip_ntoa(&ip_port.ip), ntohs(ip_port.port));
70 ntohs(ip_port.port));
71} 70}
72/* 71/*
73void printpackets(Data test) 72void printpackets(Data test)
@@ -152,30 +151,45 @@ void printconnection(int connection_id)
152 151
153int main(int argc, char *argv[]) 152int main(int argc, char *argv[])
154{ 153{
155 if (argc < 4) { 154 /* let user override default by cmdline */
156 printf("usage: %s ip port filename\n", argv[0]); 155 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
156 int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
157 if (argvoffset < 0)
158 exit(1);
159
160 if (argc < argvoffset + 4) {
161 printf("Usage: %s [--ipv4|--ipv6] ip port filename\n", argv[0]);
157 exit(0); 162 exit(0);
158 } 163 }
159 164
160 uint8_t buffer[512]; 165 uint8_t buffer[512];
161 int read; 166 int read;
162 167
163 FILE *file = fopen(argv[3], "rb"); 168 FILE *file = fopen(argv[argvoffset + 3], "rb");
164 169
165 if (file == NULL) 170 if (file == NULL) {
171 printf("Failed to open file \"%s\".\n", argv[argvoffset + 3]);
166 return 1; 172 return 1;
173 }
167 174
168 175
169 /* initialize networking */ 176 /* initialize networking */
170 /* bind to ip 0.0.0.0:PORT */ 177 /* bind to ip 0.0.0.0:PORT */
171 IP ip; 178 IP ip;
172 ip.uint32 = 0; 179 ip_init(&ip, ipv6enabled);
180
173 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); 181 Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT));
174 perror("Initialization"); 182 perror("Initialization");
183
175 IP_Port serverip; 184 IP_Port serverip;
176 serverip.ip.uint32 = inet_addr(argv[1]); 185 ip_init(&serverip.ip, ipv6enabled);
177 serverip.port = htons(atoi(argv[2])); 186 if (!addr_resolve(argv[argvoffset + 1], &serverip.ip)) {
187 printf("Failed to convert \"%s\" into an IP address.\n", argv[argvoffset + 1]);
188 return 1;
189 }
190 serverip.port = htons(atoi(argv[argvoffset + 2]));
178 printip(serverip); 191 printip(serverip);
192
179 int connection = new_connection(ludp, serverip); 193 int connection = new_connection(ludp, serverip);
180 uint64_t timer = current_time(); 194 uint64_t timer = current_time();
181 195