summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorDiadlo <polsha3@gmail.com>2017-01-07 11:28:53 +0300
committerDiadlo <polsha3@gmail.com>2017-02-26 23:16:16 +0300
commitb19a9e54643eceaa52e71c0f38fa2ecae5a6809e (patch)
tree4c6fff0a086988ab21636e88dbf65c2e40a76a67 /testing
parentb2d04eae9d9b76523b877a9e5efd5989f83b143d (diff)
Add part of platform-independent network API implementation
socket -> net_socket htons -> net_htons htonl -> net_htonl connect -> net_connect sendto -> net_sendto_ip4 getaddrinfo -> net_getipport sa_family_t -> Family
Diffstat (limited to 'testing')
-rw-r--r--testing/DHT_test.c10
-rw-r--r--testing/Messenger_test.c2
-rw-r--r--testing/dns3_test.c31
3 files changed, 14 insertions, 29 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index c42dc053..536217fe 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -88,16 +88,16 @@ static void print_assoc(IPPTsPng *assoc, uint8_t ours)
88{ 88{
89 IP_Port *ipp = &assoc->ip_port; 89 IP_Port *ipp = &assoc->ip_port;
90 char ip_str[IP_NTOA_LEN]; 90 char ip_str[IP_NTOA_LEN];
91 printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), ntohs(ipp->port)); 91 printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), net_ntohs(ipp->port));
92 printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp); 92 printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp);
93 printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged); 93 printf("\nLast pinged: %llu\n", (long long unsigned int) assoc->last_pinged);
94 94
95 ipp = &assoc->ret_ip_port; 95 ipp = &assoc->ret_ip_port;
96 96
97 if (ours) { 97 if (ours) {
98 printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), ntohs(ipp->port)); 98 printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), net_ntohs(ipp->port));
99 } else { 99 } else {
100 printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), ntohs(ipp->port)); 100 printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), net_ntohs(ipp->port));
101 } 101 }
102 102
103 printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp); 103 printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp);
@@ -138,7 +138,7 @@ static void print_friendlist(DHT *dht)
138 138
139 int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip); 139 int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip);
140 char ip_str[IP_NTOA_LEN]; 140 char ip_str[IP_NTOA_LEN];
141 printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), ntohs(p_ip.port), friendok); 141 printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), net_ntohs(p_ip.port), friendok);
142 142
143 printf("\nCLIENTS IN LIST:\n\n"); 143 printf("\nCLIENTS IN LIST:\n\n");
144 144
@@ -227,7 +227,7 @@ int main(int argc, char *argv[])
227 227
228 perror("Initialization"); 228 perror("Initialization");
229 229
230 uint16_t port = htons(atoi(argv[argvoffset + 2])); 230 uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
231 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); 231 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
232 int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string); 232 int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
233 free(binary_string); 233 free(binary_string);
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 467d7988..c1a63da8 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
126 } 126 }
127 127
128 if (argc == argvoffset + 4) { 128 if (argc == argvoffset + 4) {
129 uint16_t port = htons(atoi(argv[argvoffset + 2])); 129 uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
130 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); 130 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
131 int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1], 131 int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1],
132 ipv6enabled, port, bootstrap_key); 132 ipv6enabled, port, bootstrap_key);
diff --git a/testing/dns3_test.c b/testing/dns3_test.c
index 021a09f9..37bbfadb 100644
--- a/testing/dns3_test.c
+++ b/testing/dns3_test.c
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
50 50
51 IP ip = {0}; 51 IP ip = {0};
52 ip.family = AF_INET; 52 ip.family = AF_INET;
53 Socket sock = socket(ip.family, SOCK_DGRAM, IPPROTO_UDP); 53 Socket sock = net_socket(ip.family, TOX_SOCK_DGRAM, TOX_PROTO_UDP);
54 54
55 if (!sock_valid(sock)) { 55 if (!sock_valid(sock)) {
56 return -1; 56 return -1;
@@ -60,29 +60,9 @@ int main(int argc, char *argv[])
60 return -1; 60 return -1;
61 } 61 }
62 62
63 struct sockaddr_in target; 63 uint32_t request_id;
64
65 size_t addrsize = sizeof(struct sockaddr_in);
66
67 target.sin_family = AF_INET;
68
69 fill_addr4(ip.ip4, &target.sin_addr);
70
71 target.sin_port = htons(53);
72
73 uint8_t string[1024] = {0}; 64 uint8_t string[1024] = {0};
74
75 void *d = tox_dns3_new(hex_string_to_bin(argv[2])); 65 void *d = tox_dns3_new(hex_string_to_bin(argv[2]));
76
77 unsigned int i;
78
79 uint32_t request_id;
80
81 /*
82 for (i = 0; i < 255; ++i) {
83 tox_generate_dns3_string(d, string, sizeof(string), &request_id, string, i);
84 printf("%s\n", string);
85 }*/
86 int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3])); 66 int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3]));
87 67
88 if (len == -1) { 68 if (len == -1) {
@@ -96,7 +76,11 @@ int main(int argc, char *argv[])
96 uint8_t id = rand(); 76 uint8_t id = rand();
97 uint32_t p_len = create_packet(packet, string, strlen((char *)string), id); 77 uint32_t p_len = create_packet(packet, string, strlen((char *)string), id);
98 78
99 if (sendto(sock, (char *)packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len) { 79 IP_Port ip_port;
80 ip_port.port = 53;
81 ip_port.ip = ip;
82
83 if (net_sendto_ip4(sock, (char *)packet, p_len, ip_port) != p_len) {
100 return -1; 84 return -1;
101 } 85 }
102 86
@@ -107,6 +91,7 @@ int main(int argc, char *argv[])
107 return -1; 91 return -1;
108 } 92 }
109 93
94 unsigned int i;
110 for (i = r_len - 1; i != 0 && buffer[i] != '='; --i) { 95 for (i = r_len - 1; i != 0 && buffer[i] != '='; --i) {
111 ; 96 ;
112 } 97 }