Skip to content

Commit c495a46

Browse files
tanushree27dscho
authored andcommitted
mingw: remove obsolete IPv6-related code
To support IPv6, Git provided fall back functions for Windows versions that did not support IPv6. However, as Git dropped support for Windows XP and prior, those functions are not needed anymore. Removed those fallbacks by reverting commit[1] and using the functions directly (without 'ipv6_' prefix). [1] fe3b2b7. Signed-off-by: tanushree27 <[email protected]>
1 parent e1dfaac commit c495a46

File tree

2 files changed

+1
-193
lines changed

2 files changed

+1
-193
lines changed

compat/mingw.c

Lines changed: 1 addition & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,142 +2100,10 @@ int mingw_putenv(const char *namevalue)
21002100
return result ? 0 : -1;
21012101
}
21022102

2103-
/*
2104-
* Note, this isn't a complete replacement for getaddrinfo. It assumes
2105-
* that service contains a numerical port, or that it is null. It
2106-
* does a simple search using gethostbyname, and returns one IPv4 host
2107-
* if one was found.
2108-
*/
2109-
static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
2110-
const struct addrinfo *hints,
2111-
struct addrinfo **res)
2112-
{
2113-
struct hostent *h = NULL;
2114-
struct addrinfo *ai;
2115-
struct sockaddr_in *sin;
2116-
2117-
if (node) {
2118-
h = gethostbyname(node);
2119-
if (!h)
2120-
return WSAGetLastError();
2121-
}
2122-
2123-
ai = xmalloc(sizeof(struct addrinfo));
2124-
*res = ai;
2125-
ai->ai_flags = 0;
2126-
ai->ai_family = AF_INET;
2127-
ai->ai_socktype = hints ? hints->ai_socktype : 0;
2128-
switch (ai->ai_socktype) {
2129-
case SOCK_STREAM:
2130-
ai->ai_protocol = IPPROTO_TCP;
2131-
break;
2132-
case SOCK_DGRAM:
2133-
ai->ai_protocol = IPPROTO_UDP;
2134-
break;
2135-
default:
2136-
ai->ai_protocol = 0;
2137-
break;
2138-
}
2139-
ai->ai_addrlen = sizeof(struct sockaddr_in);
2140-
if (hints && (hints->ai_flags & AI_CANONNAME))
2141-
ai->ai_canonname = h ? xstrdup(h->h_name) : NULL;
2142-
else
2143-
ai->ai_canonname = NULL;
2144-
2145-
sin = xcalloc(1, ai->ai_addrlen);
2146-
sin->sin_family = AF_INET;
2147-
/* Note: getaddrinfo is supposed to allow service to be a string,
2148-
* which should be looked up using getservbyname. This is
2149-
* currently not implemented */
2150-
if (service)
2151-
sin->sin_port = htons(atoi(service));
2152-
if (h)
2153-
sin->sin_addr = *(struct in_addr *)h->h_addr;
2154-
else if (hints && (hints->ai_flags & AI_PASSIVE))
2155-
sin->sin_addr.s_addr = INADDR_ANY;
2156-
else
2157-
sin->sin_addr.s_addr = INADDR_LOOPBACK;
2158-
ai->ai_addr = (struct sockaddr *)sin;
2159-
ai->ai_next = NULL;
2160-
return 0;
2161-
}
2162-
2163-
static void WSAAPI freeaddrinfo_stub(struct addrinfo *res)
2164-
{
2165-
free(res->ai_canonname);
2166-
free(res->ai_addr);
2167-
free(res);
2168-
}
2169-
2170-
static int WSAAPI getnameinfo_stub(const struct sockaddr *sa, socklen_t salen,
2171-
char *host, DWORD hostlen,
2172-
char *serv, DWORD servlen, int flags)
2173-
{
2174-
const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
2175-
if (sa->sa_family != AF_INET)
2176-
return EAI_FAMILY;
2177-
if (!host && !serv)
2178-
return EAI_NONAME;
2179-
2180-
if (host && hostlen > 0) {
2181-
struct hostent *ent = NULL;
2182-
if (!(flags & NI_NUMERICHOST))
2183-
ent = gethostbyaddr((const char *)&sin->sin_addr,
2184-
sizeof(sin->sin_addr), AF_INET);
2185-
2186-
if (ent)
2187-
snprintf(host, hostlen, "%s", ent->h_name);
2188-
else if (flags & NI_NAMEREQD)
2189-
return EAI_NONAME;
2190-
else
2191-
snprintf(host, hostlen, "%s", inet_ntoa(sin->sin_addr));
2192-
}
2193-
2194-
if (serv && servlen > 0) {
2195-
struct servent *ent = NULL;
2196-
if (!(flags & NI_NUMERICSERV))
2197-
ent = getservbyport(sin->sin_port,
2198-
flags & NI_DGRAM ? "udp" : "tcp");
2199-
2200-
if (ent)
2201-
snprintf(serv, servlen, "%s", ent->s_name);
2202-
else
2203-
snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
2204-
}
2205-
2206-
return 0;
2207-
}
2208-
2209-
static HMODULE ipv6_dll = NULL;
2210-
static void (WSAAPI *ipv6_freeaddrinfo)(struct addrinfo *res);
2211-
static int (WSAAPI *ipv6_getaddrinfo)(const char *node, const char *service,
2212-
const struct addrinfo *hints,
2213-
struct addrinfo **res);
2214-
static int (WSAAPI *ipv6_getnameinfo)(const struct sockaddr *sa, socklen_t salen,
2215-
char *host, DWORD hostlen,
2216-
char *serv, DWORD servlen, int flags);
2217-
/*
2218-
* gai_strerror is an inline function in the ws2tcpip.h header, so we
2219-
* don't need to try to load that one dynamically.
2220-
*/
2221-
2222-
static void socket_cleanup(void)
2223-
{
2224-
WSACleanup();
2225-
if (ipv6_dll)
2226-
FreeLibrary(ipv6_dll);
2227-
ipv6_dll = NULL;
2228-
ipv6_freeaddrinfo = freeaddrinfo_stub;
2229-
ipv6_getaddrinfo = getaddrinfo_stub;
2230-
ipv6_getnameinfo = getnameinfo_stub;
2231-
}
2232-
22332103
static void ensure_socket_initialization(void)
22342104
{
22352105
WSADATA wsa;
22362106
static int initialized = 0;
2237-
const char *libraries[] = { "ws2_32.dll", "wship6.dll", NULL };
2238-
const char **name;
22392107

22402108
if (initialized)
22412109
return;
@@ -2244,35 +2112,7 @@ static void ensure_socket_initialization(void)
22442112
die("unable to initialize winsock subsystem, error %d",
22452113
WSAGetLastError());
22462114

2247-
for (name = libraries; *name; name++) {
2248-
ipv6_dll = LoadLibraryExA(*name, NULL,
2249-
LOAD_LIBRARY_SEARCH_SYSTEM32);
2250-
if (!ipv6_dll)
2251-
continue;
2252-
2253-
ipv6_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *))
2254-
GetProcAddress(ipv6_dll, "freeaddrinfo");
2255-
ipv6_getaddrinfo = (int (WSAAPI *)(const char *, const char *,
2256-
const struct addrinfo *,
2257-
struct addrinfo **))
2258-
GetProcAddress(ipv6_dll, "getaddrinfo");
2259-
ipv6_getnameinfo = (int (WSAAPI *)(const struct sockaddr *,
2260-
socklen_t, char *, DWORD,
2261-
char *, DWORD, int))
2262-
GetProcAddress(ipv6_dll, "getnameinfo");
2263-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2264-
FreeLibrary(ipv6_dll);
2265-
ipv6_dll = NULL;
2266-
} else
2267-
break;
2268-
}
2269-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2270-
ipv6_freeaddrinfo = freeaddrinfo_stub;
2271-
ipv6_getaddrinfo = getaddrinfo_stub;
2272-
ipv6_getnameinfo = getnameinfo_stub;
2273-
}
2274-
2275-
atexit(socket_cleanup);
2115+
atexit((void(*)(void)) WSACleanup);
22762116
initialized = 1;
22772117
}
22782118

@@ -2290,26 +2130,6 @@ struct hostent *mingw_gethostbyname(const char *host)
22902130
return gethostbyname(host);
22912131
}
22922132

2293-
void mingw_freeaddrinfo(struct addrinfo *res)
2294-
{
2295-
ipv6_freeaddrinfo(res);
2296-
}
2297-
2298-
int mingw_getaddrinfo(const char *node, const char *service,
2299-
const struct addrinfo *hints, struct addrinfo **res)
2300-
{
2301-
ensure_socket_initialization();
2302-
return ipv6_getaddrinfo(node, service, hints, res);
2303-
}
2304-
2305-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
2306-
char *host, DWORD hostlen, char *serv, DWORD servlen,
2307-
int flags)
2308-
{
2309-
ensure_socket_initialization();
2310-
return ipv6_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
2311-
}
2312-
23132133
int mingw_socket(int domain, int type, int protocol)
23142134
{
23152135
int sockfd;

compat/mingw.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,6 @@ int mingw_gethostname(char *host, int namelen);
297297
struct hostent *mingw_gethostbyname(const char *host);
298298
#define gethostbyname mingw_gethostbyname
299299

300-
void mingw_freeaddrinfo(struct addrinfo *res);
301-
#define freeaddrinfo mingw_freeaddrinfo
302-
303-
int mingw_getaddrinfo(const char *node, const char *service,
304-
const struct addrinfo *hints, struct addrinfo **res);
305-
#define getaddrinfo mingw_getaddrinfo
306-
307-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
308-
char *host, DWORD hostlen, char *serv, DWORD servlen,
309-
int flags);
310-
#define getnameinfo mingw_getnameinfo
311-
312300
int mingw_socket(int domain, int type, int protocol);
313301
#define socket mingw_socket
314302

0 commit comments

Comments
 (0)