patch 9.2.0183: channel: using deprecated networking APIs
Commit:
https://github.com/vim/vim/commit/cce17de8450a8b8e890aea4c67a02527c1db7b24
Author: Yasuhiro Matsumoto <[email protected]>
Date: Mon Mar 16 21:59:40 2026 +0000
patch 9.2.0183: channel: using deprecated networking APIs
Problem: gethostbyname() and inet_ntoa() are deprecated and cause
build errors on modern MSVC versions.
Solution: Use getaddrinfo() and inet_ntop() when FEAT_IPV6 and
HAVE_INET_NTOP are defined. Keep the old functions as
fallbacks for legacy platforms (Yasuhiro Matsumoto).
closes: #19719
Signed-off-by: Yasuhiro Matsumoto <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/channel.c b/src/channel.c
index 6f06517fd..caa382da7 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -1507,7 +1507,9 @@ channel_listen(
{
int sd = -1;
struct sockaddr_in server;
+#ifndef FEAT_IPV6
struct hostent *host;
+#endif
int val = 1;
channel_T *channel;
@@ -1529,6 +1531,26 @@ channel_listen(
server.sin_port = htons(port_in);
if (hostname != NULL && *hostname != NUL)
{
+#ifdef FEAT_IPV6
+ struct addrinfo hints;
+ struct addrinfo *res = NULL;
+ int err;
+
+ CLEAR_FIELD(hints);
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ if ((err = getaddrinfo(hostname, NULL, &hints, &res)) != 0)
+ {
+ ch_error(channel, "in getaddrinfo() in channel_listen()");
+ PERROR(_(e_gethostbyname_in_channel_listen));
+ channel_free(channel);
+ return NULL;
+ }
+ memcpy(&server.sin_addr,
+ &((struct sockaddr_in *)res->ai_addr)->sin_addr,
+ sizeof(server.sin_addr));
+ freeaddrinfo(res);
+#else
if ((host = gethostbyname(hostname)) == NULL)
{
ch_error(channel, "in gethostbyname() in channel_listen()");
@@ -1544,6 +1566,7 @@ channel_listen(
memcpy(&p, &host->h_addr_list[0], sizeof(p));
memcpy((char *)&server.sin_addr, p, host->h_length);
}
+#endif
}
else
server.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -4202,9 +4225,22 @@ channel_read(channel_T *channel, ch_part_T part, char
*func)
newchannel->ch_to_be_closed |= (1U << PART_SOCK);
if (client.ss_family == AF_INET)
+ {
+#ifdef HAVE_INET_NTOP
+ char addr[INET_ADDRSTRLEN];
+
+ inet_ntop(AF_INET,
+ &((struct sockaddr_in*)&client)->sin_addr,
+ addr, sizeof(addr));
+ vim_snprintf((char *)namebuf, sizeof(namebuf), "%s:%d",
+ addr,
+ ntohs(((struct sockaddr_in*)&client)->sin_port));
+#else
vim_snprintf((char *)namebuf, sizeof(namebuf), "%s:%d",
inet_ntoa(((struct sockaddr_in*)&client)->sin_addr),
ntohs(((struct sockaddr_in*)&client)->sin_port));
+#endif
+ }
#ifdef HAVE_INET_NTOP
else if (client.ss_family == AF_INET6)
{
diff --git a/src/version.c b/src/version.c
index 8b3b8e952..60b86018f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 183,
/**/
182,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1w2GDH-008xUv-Cv%40256bit.org.