File tox_bootstrap_json.c changed (mode: 100644) (index 61e9f69..61c6bc0) |
... |
... |
void do_bootstrap_file(Tox *tox, const char *json_file) |
61 |
61 |
continue; |
continue; |
62 |
62 |
} |
} |
63 |
63 |
|
|
64 |
|
if (!isValidIPv4(ipv4->valuestring)) { |
|
|
64 |
|
if (!is_valid_ipv4(ipv4->valuestring) && !is_valid_ipv6(ipv6->valuestring)) { |
65 |
65 |
log_printf(L_INFO, "Skipping \"%s:%d\" %s\n", ipv4->valuestring, port->valueint, pk->valuestring); |
log_printf(L_INFO, "Skipping \"%s:%d\" %s\n", ipv4->valuestring, port->valueint, pk->valuestring); |
66 |
66 |
continue; |
continue; |
67 |
67 |
} |
} |
68 |
68 |
|
|
69 |
|
log_printf(L_INFO, "Bootstrapping from \"%s:%d\" %s\n", ipv4->valuestring, port->valueint, pk->valuestring); |
|
70 |
|
|
|
71 |
69 |
/* Could have used sodium here, but did not want to change dependencies. Alternative is: |
/* Could have used sodium here, but did not want to change dependencies. Alternative is: |
72 |
70 |
sodium_hex2bin(key_bin, sizeof(key_bin), pk->valuestring, sizeof(pk->valuestring)-1, NULL, NULL, NULL); |
sodium_hex2bin(key_bin, sizeof(key_bin), pk->valuestring, sizeof(pk->valuestring)-1, NULL, NULL, NULL); |
73 |
71 |
*/ |
*/ |
74 |
72 |
hex_string_to_bin(pk->valuestring, sizeof(pk->valuestring)-1, key_bin); |
hex_string_to_bin(pk->valuestring, sizeof(pk->valuestring)-1, key_bin); |
75 |
73 |
|
|
76 |
|
tox_bootstrap(tox, ipv4->valuestring, port->valueint, key_bin, NULL); |
|
|
74 |
|
if(is_valid_ipv4(ipv4->valuestring)) |
|
75 |
|
{ |
|
76 |
|
tox_bootstrap(tox, ipv4->valuestring, port->valueint, key_bin, NULL); |
|
77 |
|
log_printf(L_INFO, "Bootstrapping from \"%s:%d\" %s\n", ipv4->valuestring, port->valueint, pk->valuestring); |
|
78 |
|
} |
|
79 |
|
|
|
80 |
|
if(is_valid_ipv6(ipv6->valuestring)) |
|
81 |
|
{ |
|
82 |
|
tox_bootstrap(tox, ipv6->valuestring, port->valueint, key_bin, NULL); |
|
83 |
|
log_printf(L_INFO, "Bootstrapping from \"%s:%d\" %s\n", ipv6->valuestring, port->valueint, pk->valuestring); |
|
84 |
|
} |
77 |
85 |
|
|
78 |
86 |
tcp_ports = cJSON_GetObjectItemCaseSensitive(node, "tcp_ports"); |
tcp_ports = cJSON_GetObjectItemCaseSensitive(node, "tcp_ports"); |
79 |
87 |
cJSON_ArrayForEach(tcp_port, tcp_ports) { |
cJSON_ArrayForEach(tcp_port, tcp_ports) { |
File util.c changed (mode: 100644) (index 5299415..0587e30) |
1 |
1 |
#include "log.h" |
#include "log.h" |
2 |
2 |
#include "util.h" |
#include "util.h" |
|
3 |
|
#include <arpa/inet.h> |
3 |
4 |
#include <string.h> |
#include <string.h> |
4 |
5 |
#include <tox/tox.h> |
#include <tox/tox.h> |
5 |
6 |
#include <stdio.h> |
#include <stdio.h> |
|
... |
... |
size_t hex_string_to_bin(const char *hex_string, size_t hex_len, uint8_t *bytes) |
228 |
229 |
} |
} |
229 |
230 |
|
|
230 |
231 |
/* Very stupid test to filter out hostnames */ |
/* Very stupid test to filter out hostnames */ |
231 |
|
bool isValidIPv4(const char *ip_address) |
|
|
232 |
|
bool is_valid_ipv4(const char *ip_address) |
232 |
233 |
{ |
{ |
233 |
|
unsigned int a,b,c,d; |
|
234 |
|
return sscanf(ip_address,"%u.%u.%u.%u", &a, &b, &c, &d) == 4; |
|
|
234 |
|
unsigned int a,b,c,d; |
|
235 |
|
return sscanf(ip_address,"%u.%u.%u.%u", &a, &b, &c, &d) == 4; |
|
236 |
|
} |
|
237 |
|
|
|
238 |
|
bool is_valid_ipv6(const char *ip_address) |
|
239 |
|
{ |
|
240 |
|
struct in6_addr result; |
|
241 |
|
return (inet_pton(AF_INET6, ip_address, &result) == 1); |
235 |
242 |
} |
} |
File util.h changed (mode: 100644) (index 1d3b339..fea57af) |
... |
... |
const char *readable_connection_status(TOX_CONNECTION status); |
16 |
16 |
int parse_local_port_forward(char *string, int *local_port, char **hostname, int *remote_port); |
int parse_local_port_forward(char *string, int *local_port, char **hostname, int *remote_port); |
17 |
17 |
int parse_pipe_port_forward(char *string, char **hostname, int *remote_port); |
int parse_pipe_port_forward(char *string, char **hostname, int *remote_port); |
18 |
18 |
size_t hex_string_to_bin(const char *hex_string, size_t hex_len, uint8_t *bytes); |
size_t hex_string_to_bin(const char *hex_string, size_t hex_len, uint8_t *bytes); |
19 |
|
bool isValidIPv4(const char *ip_address); |
|
|
19 |
|
bool is_valid_ipv4(const char *ip_address); |
|
20 |
|
bool is_valid_ipv6(const char *ip_address); |
20 |
21 |
|
|
21 |
22 |
#endif |
#endif |