[Openvpn-devel,v1] dns: store IPv4 addresses in network byte order

Message ID 20241213164552.265863-1-frank@lichtenheld.com
State Accepted
Headers show
Series [Openvpn-devel,v1] dns: store IPv4 addresses in network byte order | expand

Commit Message

Frank Lichtenheld Dec. 13, 2024, 4:45 p.m. UTC
From: Heiko Hund <heiko@ist.eigentlich.net>

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 <heiko@ist.eigentlich.net>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/834
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>

Comments

Gert Doering Dec. 20, 2024, 9:41 p.m. UTC | #1
Patch looks good, ACK from Frank, all *consumers* of addr[].in.a4.s_addr
(today) are "print_in_addr_t()" calls which have a flag to deal with
the changed byte order.

Have not actually tested anything, just test compiled.

Your patch has been applied to the master branch.

commit 6f2d222c92bb4555dc931c2aed3510a64bd53df3
Author: Heiko Hund
Date:   Fri Dec 13 17:45:52 2024 +0100

     dns: store IPv4 addresses in network byte order

     Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Message-Id: <20241213164552.265863-1-frank@lichtenheld.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30111.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c
index 0539ca5..15e7322 100644
--- a/src/openvpn/dns.c
+++ b/src/openvpn/dns.c
@@ -121,7 +121,7 @@ 
     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
     {
@@ -384,7 +384,7 @@ 
             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
             {
@@ -443,7 +443,7 @@ 
             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