Skip to content

Commit

Permalink
dns: store IPv4 addresses in network byte order
Browse files Browse the repository at this point in the history
This is done so that inet_ntop(3) can be used with IPv4 name server
addresses. It expects the binary address in network byte order. If they
are not that way the address octets are reversed.

Change-Id: I81d4bb0abdd421f5ba260c10c610918652334a4d
Signed-off-by: Heiko Hund <[email protected]>
Acked-by: Frank Lichtenheld <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg30111.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
d12fk authored and cron2 committed Dec 20, 2024
1 parent baa9192 commit 6f2d222
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/openvpn/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ dns_server_addr_parse(struct dns_server *server, const char *addr)
if (ai->ai_family == AF_INET)
{
struct sockaddr_in *sin = (struct sockaddr_in *)ai->ai_addr;
server->addr[server->addr_count].in.a4.s_addr = ntohl(sin->sin_addr.s_addr);
server->addr[server->addr_count].in.a4.s_addr = sin->sin_addr.s_addr;
}
else
{
Expand Down Expand Up @@ -384,7 +384,7 @@ setenv_dns_options(const struct dns_options *o, struct env_set *es)
if (s->addr[j].family == AF_INET)
{
setenv_dns_option(es, "dns_server_%d_address_%d", i, j + 1,
print_in_addr_t(s->addr[j].in.a4.s_addr, 0, &gc));
print_in_addr_t(s->addr[j].in.a4.s_addr, IA_NET_ORDER, &gc));
}
else
{
Expand Down Expand Up @@ -443,7 +443,7 @@ show_dns_options(const struct dns_options *o)
const char *fmt_port;
if (server->addr[j].family == AF_INET)
{
addr = print_in_addr_t(server->addr[j].in.a4.s_addr, 0, &gc);
addr = print_in_addr_t(server->addr[j].in.a4.s_addr, IA_NET_ORDER, &gc);
fmt_port = " address = %s:%s";
}
else
Expand Down

0 comments on commit 6f2d222

Please sign in to comment.