diff options
Diffstat (limited to 'testing/dns3_test.c')
-rw-r--r-- | testing/dns3_test.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/testing/dns3_test.c b/testing/dns3_test.c new file mode 100644 index 00000000..69649f50 --- /dev/null +++ b/testing/dns3_test.c | |||
@@ -0,0 +1,51 @@ | |||
1 | |||
2 | |||
3 | #include "../toxdns/toxdns.h" | ||
4 | #include "../toxcore/tox.h" | ||
5 | #include "misc_tools.c" | ||
6 | |||
7 | |||
8 | int main(int argc, char *argv[]) | ||
9 | { | ||
10 | if (argc < 4) { | ||
11 | printf("Usage: %s domain domain_public_key queried_username\nEX: %s utox.org D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12 username\n", | ||
12 | argv[0], argv[0]); | ||
13 | exit(0); | ||
14 | } | ||
15 | |||
16 | uint8_t string[1024] = {0}; | ||
17 | void *d = tox_dns3_new(hex_string_to_bin(argv[2])); | ||
18 | unsigned int i; | ||
19 | uint32_t request_id; | ||
20 | /* | ||
21 | for (i = 0; i < 255; ++i) { | ||
22 | tox_generate_dns3_string(d, string, sizeof(string), &request_id, string, i); | ||
23 | printf("%s\n", string); | ||
24 | }*/ | ||
25 | int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3])); | ||
26 | |||
27 | if (len == -1) | ||
28 | return -1; | ||
29 | |||
30 | string[0] = '_'; | ||
31 | memcpy(string + len + 1, "._tox.", sizeof("._tox.")); | ||
32 | memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1])); | ||
33 | printf("Do a DNS request and find the TXT record for:\n%s\nThen paste the contents of the data contained in the id field here:\n", | ||
34 | string); | ||
35 | |||
36 | scanf("%s", string); | ||
37 | uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE]; | ||
38 | |||
39 | if (tox_decrypt_dns3_TXT(d, tox_id, string, strlen((char *)string), request_id) != 0) | ||
40 | return -1; | ||
41 | |||
42 | printf("The Tox id for username %s is:\n", argv[3]); | ||
43 | |||
44 | //unsigned int i; | ||
45 | for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) { | ||
46 | printf("%02hhX", tox_id[i]); | ||
47 | } | ||
48 | |||
49 | printf("\n"); | ||
50 | return 0; | ||
51 | } | ||