[Openvpn-devel,XS] Change in openvpn[master]: dns: store IPv4 addresses in network byte order

Message ID 6389cf62a6846c2fbb37283949b0d6308d3510da-HTML@gerrit.openvpn.net
State Superseded
Headers show
Series [Openvpn-devel,XS] Change in openvpn[master]: dns: store IPv4 addresses in network byte order | expand

Commit Message

ralf_lici (Code Review) Dec. 12, 2024, 7:47 a.m. UTC
Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/834?usp=email

to review the following change.


Change subject: dns: store IPv4 addresses in network byte order
......................................................................

dns: store IPv4 addresses in network byte order

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>
---
M src/openvpn/dns.c
1 file changed, 3 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/34/834/1

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