Skip to content

Commit

Permalink
Merge pull request #326 from pymumu/master
Browse files Browse the repository at this point in the history
Fork Sync
  • Loading branch information
PikuZheng authored Feb 3, 2025
2 parents 7fc8b0f + d7c92f0 commit 0ba1434
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ static int _dns_client_server_add(char *server_ip, char *server_host, int port,
if (server_host) {
safe_strncpy(flag_https->httphost, server_host, DNS_MAX_CNAME_LEN);
} else {
safe_strncpy(flag_https->httphost, server_ip, DNS_MAX_CNAME_LEN);
set_http_host(server_ip, port, DEFAULT_DNS_HTTPS_PORT, flag_https->httphost);
}
}
sock_type = SOCK_STREAM;
Expand Down
2 changes: 1 addition & 1 deletion src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ static int _config_server(int argc, char *argv[], dns_server_type_t type, int de
}

if (server->httphost[0] == '\0') {
safe_strncpy(server->httphost, server->server, DNS_MAX_CNAME_LEN);
set_http_host(server->server, server->port, DEFAULT_DNS_HTTPS_PORT, server->httphost);
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,23 @@ int parser_mac_address(const char *in_mac, uint8_t mac[6])
return -1;
}

int set_http_host(const char *uri_host, int port, int default_port, char *host)
{
int is_ipv6;

if (uri_host == NULL || port <= 0 || host == NULL) {
return -1;
}

is_ipv6 = check_is_ipv6(uri_host);
if (port == default_port) {
snprintf(host, DNS_MAX_CNAME_LEN, "%s%s%s", is_ipv6 == 0 ? "[" : "", uri_host, is_ipv6 == 0 ? "]" : "");
} else {
snprintf(host, DNS_MAX_CNAME_LEN, "%s%s%s:%d", is_ipv6 == 0 ? "[" : "", uri_host, is_ipv6 == 0 ? "]" : "", port);
}
return 0;
}

#if defined(DEBUG) || defined(TEST)
struct _dns_read_packet_info {
int data_len;
Expand Down
2 changes: 2 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ void daemon_close_stdfds(void);

int write_file(const char *filename, void *data, int data_len);

int set_http_host(const char *uri_host, int port, int default_port, char *host);

int dns_packet_save(const char *dir, const char *type, const char *from, const void *packet, int packet_len);

int dns_packet_debug(const char *packet_file);
Expand Down

0 comments on commit 0ba1434

Please sign in to comment.