]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0183: channel: using deprecated networking APIs v9.2.0183
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Mon, 16 Mar 2026 21:59:40 +0000 (21:59 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 16 Mar 2026 22:02:13 +0000 (22:02 +0000)
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 <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/channel.c
src/version.c

index 6f06517fd765b9aad79832011cc3028eeecede9d..caa382da75f6637a48b1c6fa9371f87f68ca2f3c 100644 (file)
@@ -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)
            {
index 8b3b8e9522d35c1d3cf699979ae2039c680caee5..60b86018f6123c8016fb8c8f59a324422f29d2fb 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    183,
 /**/
     182,
 /**/