From: "cron2 (Code Review)" Date: Wed, 18 Oct 2023 17:46:58 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="iBlz37TlZ64="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Remove last uses of inet_ntoa List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: plaisthos , openvpn-devel --iBlz37TlZ64= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/32= 6?usp=3Demail ) Change subject: Remove last uses of inet_ntoa ...................................................................... Remove last uses of inet_ntoa inet_ntoa is officially deprecated and in some places its use already causes warnings (e.g. Fedora submissions). Since we mostly use inet_ntop already, just convert the remaining usages to that. Change-Id: I052bebe720ddf26340827f25b94705945e470bfa Signed-off-by: Frank Lichtenheld Acked-by: Arne Schwabe Message-Id: <20231008103415.19625-1-frank@...2641...> URL: https://www.mail-archive.com/search?l=3Dmid&q=3D20231008103415.19625-1= -frank@...2641... Signed-off-by: Gert Doering --- M src/openvpn/manage.c M src/openvpn/route.c M src/openvpn/socket.c 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 739ed40..feb62b2 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -3058,9 +3058,11 @@ /* listen on our local TUN/TAP IP address */ struct in_addr ia; int ret; + char buf[INET_ADDRSTRLEN]; ia.s_addr =3D htonl(tun_local_ip); - ret =3D openvpn_getaddrinfo(GETADDR_PASSIVE, inet_ntoa(ia), NULL, = 0, NULL, + inet_ntop(AF_INET, &ia, buf, sizeof(buf)); + ret =3D openvpn_getaddrinfo(GETADDR_PASSIVE, buf, NULL, 0, NULL, AF_INET, &man->settings.local); ASSERT(ret=3D=3D0); man_connection_init(man); diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 9212186..ff64938 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -342,7 +342,9 @@ goto fail; } special.s_addr =3D htonl(special.s_addr); - ret =3D openvpn_getaddrinfo(0, inet_ntoa(special), NULL, 0, NULL, + char buf[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &special, buf, sizeof(buf)); + ret =3D openvpn_getaddrinfo(0, buf, NULL, 0, NULL, AF_INET, network_list); } else diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 501e023..903f98b 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -2901,16 +2901,16 @@ print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc) { struct in_addr ia; - struct buffer out =3D alloc_buf_gc(64, gc); + char *out =3D gc_malloc(INET_ADDRSTRLEN, true, gc); if (addr || !(flags & IA_EMPTY_IF_UNDEF)) { CLEAR(ia); ia.s_addr =3D (flags & IA_NET_ORDER) ? addr : htonl(addr); - buf_printf(&out, "%s", inet_ntoa(ia)); + inet_ntop(AF_INET, &ia, out, INET_ADDRSTRLEN); } - return BSTR(&out); + return out; } /* @@ -2920,16 +2920,14 @@ const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc) { - struct buffer out =3D alloc_buf_gc(64, gc); - char tmp_out_buf[64]; /* inet_ntop wants pointer to buffer */ + char *out =3D gc_malloc(INET6_ADDRSTRLEN, true, gc); if (memcmp(&a6, &in6addr_any, sizeof(a6)) !=3D 0 || !(flags & IA_EMPTY_IF_UNDEF)) { - inet_ntop(AF_INET6, &a6, tmp_out_buf, sizeof(tmp_out_buf)-1); - buf_printf(&out, "%s", tmp_out_buf ); + inet_ntop(AF_INET6, &a6, out, INET6_ADDRSTRLEN); } - return BSTR(&out); + return out; } /* @@ -2978,7 +2976,7 @@ { char name_buf[256]; - char buf[128]; + char buf[INET6_ADDRSTRLEN]; switch (addr->addr.sa.sa_family) { case AF_INET: @@ -2991,7 +2989,8 @@ openvpn_snprintf(name_buf, sizeof(name_buf), "%s", name_pr= efix); } - setenv_str(es, name_buf, inet_ntoa(addr->addr.in4.sin_addr)); + inet_ntop(AF_INET, &addr->addr.in4.sin_addr, buf, sizeof(buf)); + setenv_str(es, name_buf, buf); if ((flags & SA_IP_PORT) && addr->addr.in4.sin_port) { @@ -3007,13 +3006,12 @@ memcpy(&ia.s_addr, &addr->addr.in6.sin6_addr.s6_addr[12], sizeof(ia.s_addr)); openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip", name= _prefix); - openvpn_snprintf(buf, sizeof(buf), "%s", inet_ntoa(ia) ); + inet_ntop(AF_INET, &ia, buf, sizeof(buf)); } else { openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip6", nam= e_prefix); - getnameinfo(&addr->addr.sa, sizeof(struct sockaddr_in6), - buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); + inet_ntop(AF_INET6, &addr->addr.in6.sin6_addr, buf, sizeof= (buf)); } setenv_str(es, name_buf, buf); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/326?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I052bebe720ddf26340827f25b94705945e470bfa Gerrit-Change-Number: 326 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --iBlz37TlZ64= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Remove last uses of inet_ntoa

inet_ntoa= is officially deprecated and in some places
its use already causes warn= ings (e.g. Fedora submissions).
Since we mostly use inet_ntop already, j= ust convert the
remaining usages to that.

Change-Id: I052bebe720d= df26340827f25b94705945e470bfa
Signed-off-by: Frank Lichtenheld <frank= @...2641...>
Acked-by: Arne Schwabe <arne-openvpn@...1227...>Message-Id: <20231008103415.19625-1-frank@...2641...>
URL: https= ://www.mail-archive.com/search?l=3Dmid&q=3D20231008103415.19625-1-frank= @...2641...
Signed-off-by: Gert Doering <gert@...1296...>
---M src/openvpn/manage.c
M src/openvpn/route.c
M src/openvpn/socket.c=
3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 739ed40..feb62b2 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -3058,9 +3058,= 11 @@
/* listen on our local TUN/TAP IP address */=
struct in_addr ia;
int r= et;
+ char buf= [INET_ADDRSTRLEN];

ia.s_addr =3D= htonl(tun_local_ip);
-= ret =3D openvpn_getaddrinfo(GETADDR_PASSIVE, inet_ntoa(ia), NULL, 0= , NULL,
+ inet= _ntop(AF_INET, &ia, buf, sizeof(buf));
+ ret =3D openvpn_getaddrinfo(GETADDR_PASSIVE,= buf, NULL, 0, NULL,
AF_= INET, &man->settings.local);
ASSERT(ret=3D= =3D0);
man_connection_init(man);
d= iff --git a/src/openvpn/route.c b/src/openvpn/route.c
index= 9212186..ff64938 100644
--- a/src/openvpn/route.c+++ b/src/openvpn/route.c
@@ -342,7 +342,9 @@

goto fail;
}
special.s_addr =3D htonl(special.s_addr);
- ret =3D openvpn_getaddrinfo(0, inet= _ntoa(special), NULL, 0, NULL,
+ char buf[INET_ADDRSTRLEN];
+ inet_ntop(AF_INET, &special, buf, siz= eof(buf));
+ r= et =3D openvpn_getaddrinfo(0, buf, NULL, 0, NULL,
= AF_INET, network_list);
}
else
diff --git a/src/openvpn/socket.c b= /src/openvpn/socket.c
index 501e023..903f98b 100644<= br>--- a/src/openvpn/socket.c
+++ b/src/openvpn/socke= t.c
@@ -2901,16 +2901,16 @@
print_in_addr_= t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
= {
struct in_addr ia;
- struct buffer out =3D alloc_buf_gc(64, gc);=
+ char *out =3D gc_mallo= c(INET_ADDRSTRLEN, true, gc);

if (ad= dr || !(flags & IA_EMPTY_IF_UNDEF))
{
CLEAR(ia);

ia.s_addr =3D (flags &= IA_NET_ORDER) ? addr : htonl(addr);

- buf_printf(&out, "%s"= ;, inet_ntoa(ia));
+ = inet_ntop(AF_INET, &ia, out, INET_ADDRSTRLEN);
= }
- return BSTR(= &out);
+ retur= n out;
}

/*
<= span>@@ -2920,16 +2920,14 @@
const char *
= print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc= )
{
- = struct buffer out =3D alloc_buf_gc(64, gc);
- char tmp_out_buf[64]; /* inet_ntop wants= pointer to buffer */
+ char *out =3D gc_malloc(INET6_ADDRSTRLEN, true, gc);
=
if (memcmp(&a6, &in6addr_any, sizeof(a6)) != =3D 0
|| !(flags & IA_EMPTY_IF_UNDEF))<= br> {
- = inet_ntop(AF_INET6, &a6, tmp_out_buf, sizeof(tmp_out_buf)-1);<= br>- buf_printf(&out, = "%s", tmp_out_buf );
+ inet_ntop(AF_INET6, &a6, out, INET6_ADDRSTRLEN);

}
- = return BSTR(&out);
+ return out;
}

= /*
@@ -2978,7 +2976,7 @@
{
char name_buf[256];

- char buf[128];
+ char buf[INET6_ADDRSTRLEN];
s= witch (addr->addr.sa.sa_family)
{
= case AF_INET:
@@ -2991,7 +2989,8 @@
openvpn_snprintf(name_buf, sizeof(name_buf), "%s&quo= t;, name_prefix);
}
- setenv_str(es, nam= e_buf, inet_ntoa(addr->addr.in4.sin_addr));
+ inet_ntop(AF_INET, &addr->add= r.in4.sin_addr, buf, sizeof(buf));
+ setenv_str(es, name_buf, buf);
=
if ((flags & SA_IP_PORT) && addr-= >addr.in4.sin_port)
{
@@ -3= 007,13 +3006,12 @@
memcpy(&ia.s_addr, = &addr->addr.in6.sin6_addr.s6_addr[12],
= sizeof(ia.s_addr));
openvpn_snp= rintf(name_buf, sizeof(name_buf), "%s_ip", name_prefix);- openvpn_snprin= tf(buf, sizeof(buf), "%s", inet_ntoa(ia) );
+ inet_ntop(AF_INET, &i= a, buf, sizeof(buf));
}
= else
{
= openvpn_snprintf(name_buf, sizeof(name_buf), "%s_ip6", name_pref= ix);
- g= etnameinfo(&addr->addr.sa, sizeof(struct sockaddr_in6),
- buf, s= izeof(buf), NULL, 0, NI_NUMERICHOST);
+ inet_ntop(AF_INET6, &addr->addr.in= 6.sin6_addr, buf, sizeof(buf));
}
setenv_str(es, name_buf, buf);

To view, visit change 326. To unsubscribe, or for hel= p writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I052bebe720ddf26340827f25b94= 705945e470bfa
Gerrit-Change-Number: 326
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--iBlz37TlZ64=--