mirror of
https://github.com/yarrick/iodine.git
synced 2025-04-04 05:43:33 +03:00
Store the length of name servers addresses
Always passing sizeof(struct sockaddr_storage) only works, by accident, on Linux. It fails on macOS and BSD.
This commit is contained in:
parent
756dc2005d
commit
dd1d12e8fb
3 changed files with 12 additions and 6 deletions
|
@ -352,8 +352,8 @@ send_query(uint8_t *hostname)
|
|||
|
||||
DEBUG(4, " Sendquery: id %5d name[0] '%c'", q.id, hostname[0]);
|
||||
|
||||
sendto(this.dns_fd, packet, len, 0, (struct sockaddr*) &this.nameserv_addrs[this.current_nameserver],
|
||||
sizeof(struct sockaddr_storage));
|
||||
sendto(this.dns_fd, packet, len, 0, (struct sockaddr*) &this.nameserv_addrs[this.current_nameserver].addr,
|
||||
this.nameserv_addrs[this.current_nameserver].len);
|
||||
|
||||
client_rotate_nameserver();
|
||||
|
||||
|
|
|
@ -26,6 +26,11 @@ extern int stats;
|
|||
#define PENDING_QUERIES_LENGTH (MAX(this.windowsize_up, this.windowsize_down) * 4)
|
||||
#define INSTANCE this
|
||||
|
||||
struct nameserv {
|
||||
struct sockaddr_storage addr;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct client_instance {
|
||||
int max_downstream_frag_size;
|
||||
int autodetect_frag_size;
|
||||
|
@ -37,7 +42,7 @@ struct client_instance {
|
|||
/* DNS nameserver info */
|
||||
char **nameserv_hosts;
|
||||
size_t nameserv_hosts_len;
|
||||
struct sockaddr_storage *nameserv_addrs;
|
||||
struct nameserv *nameserv_addrs;
|
||||
size_t nameserv_addrs_count;
|
||||
int current_nameserver;
|
||||
struct sockaddr_storage raw_serv;
|
||||
|
|
|
@ -622,7 +622,7 @@ main(int argc, char **argv)
|
|||
|
||||
// Preallocate memory with expected number of hosts
|
||||
this.nameserv_hosts = malloc(sizeof(char *) * this.nameserv_hosts_len);
|
||||
this.nameserv_addrs = malloc(sizeof(struct sockaddr_storage) * this.nameserv_hosts_len);
|
||||
this.nameserv_addrs = malloc(sizeof(struct nameserv) * this.nameserv_hosts_len);
|
||||
|
||||
if (argc == 0) {
|
||||
usage();
|
||||
|
@ -644,7 +644,8 @@ main(int argc, char **argv)
|
|||
errx(1, "Cannot lookup nameserver '%s': %s ",
|
||||
nameserv_host, gai_strerror(nameservaddr_len));
|
||||
}
|
||||
memcpy(&this.nameserv_addrs[n], &nameservaddr, sizeof(struct sockaddr_storage));
|
||||
this.nameserv_addrs[n].len = nameservaddr_len;
|
||||
memcpy(&this.nameserv_addrs[n].addr, &nameservaddr, sizeof(struct sockaddr_storage));
|
||||
this.nameserv_addrs_count ++;
|
||||
nameserv_host = NULL;
|
||||
}
|
||||
|
@ -733,7 +734,7 @@ main(int argc, char **argv)
|
|||
|
||||
fprintf(stderr, "Sending DNS queries for %s to ", this.topdomain);
|
||||
for (int a = 0; a < this.nameserv_addrs_count; a++)
|
||||
fprintf(stderr, "%s%s", format_addr(&this.nameserv_addrs[a], sizeof(struct sockaddr_storage)),
|
||||
fprintf(stderr, "%s%s", format_addr(&this.nameserv_addrs[a].addr, this.nameserv_addrs[a].len),
|
||||
(a != this.nameserv_addrs_count - 1) ? ", " : "");
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue