Skip to content

Commit 28f1d8e

Browse files
committed
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 d4f95fc commit 28f1d8e

File tree

2 files changed

+3
-193
lines changed

2 files changed

+3
-193
lines changed

compat/mingw.c

Lines changed: 3 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,179 +2208,21 @@ int mingw_putenv(const char *namevalue)
22082208

22092209
#endif
22102210

2211-
/*
2212-
* Note, this isn't a complete replacement for getaddrinfo. It assumes
2213-
* that service contains a numerical port, or that it is null. It
2214-
* does a simple search using gethostbyname, and returns one IPv4 host
2215-
* if one was found.
2216-
*/
2217-
static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
2218-
const struct addrinfo *hints,
2219-
struct addrinfo **res)
2220-
{
2221-
struct hostent *h = NULL;
2222-
struct addrinfo *ai;
2223-
struct sockaddr_in *sin;
2224-
2225-
if (node) {
2226-
h = gethostbyname(node);
2227-
if (!h)
2228-
return WSAGetLastError();
2229-
}
2230-
2231-
ai = xmalloc(sizeof(struct addrinfo));
2232-
*res = ai;
2233-
ai->ai_flags = 0;
2234-
ai->ai_family = AF_INET;
2235-
ai->ai_socktype = hints ? hints->ai_socktype : 0;
2236-
switch (ai->ai_socktype) {
2237-
case SOCK_STREAM:
2238-
ai->ai_protocol = IPPROTO_TCP;
2239-
break;
2240-
case SOCK_DGRAM:
2241-
ai->ai_protocol = IPPROTO_UDP;
2242-
break;
2243-
default:
2244-
ai->ai_protocol = 0;
2245-
break;
2246-
}
2247-
ai->ai_addrlen = sizeof(struct sockaddr_in);
2248-
if (hints && (hints->ai_flags & AI_CANONNAME))
2249-
ai->ai_canonname = h ? xstrdup(h->h_name) : NULL;
2250-
else
2251-
ai->ai_canonname = NULL;
2252-
2253-
sin = xcalloc(1, ai->ai_addrlen);
2254-
sin->sin_family = AF_INET;
2255-
/* Note: getaddrinfo is supposed to allow service to be a string,
2256-
* which should be looked up using getservbyname. This is
2257-
* currently not implemented */
2258-
if (service)
2259-
sin->sin_port = htons(atoi(service));
2260-
if (h)
2261-
sin->sin_addr = *(struct in_addr *)h->h_addr;
2262-
else if (hints && (hints->ai_flags & AI_PASSIVE))
2263-
sin->sin_addr.s_addr = INADDR_ANY;
2264-
else
2265-
sin->sin_addr.s_addr = INADDR_LOOPBACK;
2266-
ai->ai_addr = (struct sockaddr *)sin;
2267-
ai->ai_next = NULL;
2268-
return 0;
2269-
}
2270-
2271-
static void WSAAPI freeaddrinfo_stub(struct addrinfo *res)
2272-
{
2273-
free(res->ai_canonname);
2274-
free(res->ai_addr);
2275-
free(res);
2276-
}
2277-
2278-
static int WSAAPI getnameinfo_stub(const struct sockaddr *sa, socklen_t salen,
2279-
char *host, DWORD hostlen,
2280-
char *serv, DWORD servlen, int flags)
2281-
{
2282-
const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
2283-
if (sa->sa_family != AF_INET)
2284-
return EAI_FAMILY;
2285-
if (!host && !serv)
2286-
return EAI_NONAME;
2287-
2288-
if (host && hostlen > 0) {
2289-
struct hostent *ent = NULL;
2290-
if (!(flags & NI_NUMERICHOST))
2291-
ent = gethostbyaddr((const char *)&sin->sin_addr,
2292-
sizeof(sin->sin_addr), AF_INET);
2293-
2294-
if (ent)
2295-
snprintf(host, hostlen, "%s", ent->h_name);
2296-
else if (flags & NI_NAMEREQD)
2297-
return EAI_NONAME;
2298-
else
2299-
snprintf(host, hostlen, "%s", inet_ntoa(sin->sin_addr));
2300-
}
2301-
2302-
if (serv && servlen > 0) {
2303-
struct servent *ent = NULL;
2304-
if (!(flags & NI_NUMERICSERV))
2305-
ent = getservbyport(sin->sin_port,
2306-
flags & NI_DGRAM ? "udp" : "tcp");
2307-
2308-
if (ent)
2309-
snprintf(serv, servlen, "%s", ent->s_name);
2310-
else
2311-
snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
2312-
}
2313-
2314-
return 0;
2315-
}
2316-
2317-
static HMODULE ipv6_dll = NULL;
2318-
static void (WSAAPI *ipv6_freeaddrinfo)(struct addrinfo *res);
2319-
static int (WSAAPI *ipv6_getaddrinfo)(const char *node, const char *service,
2320-
const struct addrinfo *hints,
2321-
struct addrinfo **res);
2322-
static int (WSAAPI *ipv6_getnameinfo)(const struct sockaddr *sa, socklen_t salen,
2323-
char *host, DWORD hostlen,
2324-
char *serv, DWORD servlen, int flags);
2325-
/*
2326-
* gai_strerror is an inline function in the ws2tcpip.h header, so we
2327-
* don't need to try to load that one dynamically.
2328-
*/
2329-
2330-
static void socket_cleanup(void)
2331-
{
2332-
WSACleanup();
2333-
if (ipv6_dll)
2334-
FreeLibrary(ipv6_dll);
2335-
ipv6_dll = NULL;
2336-
ipv6_freeaddrinfo = freeaddrinfo_stub;
2337-
ipv6_getaddrinfo = getaddrinfo_stub;
2338-
ipv6_getnameinfo = getnameinfo_stub;
2339-
}
23402211

23412212
static void ensure_socket_initialization(void)
23422213
{
23432214
WSADATA wsa;
23442215
static int initialized = 0;
2345-
const char *libraries[] = { "ws2_32.dll", "wship6.dll", NULL };
2346-
const char **name;
2216+
23472217

23482218
if (initialized)
23492219
return;
23502220

23512221
if (WSAStartup(MAKEWORD(2,2), &wsa))
23522222
die("unable to initialize winsock subsystem, error %d",
23532223
WSAGetLastError());
2354-
2355-
for (name = libraries; *name; name++) {
2356-
ipv6_dll = LoadLibraryExA(*name, NULL,
2357-
LOAD_LIBRARY_SEARCH_SYSTEM32);
2358-
if (!ipv6_dll)
2359-
continue;
2360-
2361-
ipv6_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *))
2362-
GetProcAddress(ipv6_dll, "freeaddrinfo");
2363-
ipv6_getaddrinfo = (int (WSAAPI *)(const char *, const char *,
2364-
const struct addrinfo *,
2365-
struct addrinfo **))
2366-
GetProcAddress(ipv6_dll, "getaddrinfo");
2367-
ipv6_getnameinfo = (int (WSAAPI *)(const struct sockaddr *,
2368-
socklen_t, char *, DWORD,
2369-
char *, DWORD, int))
2370-
GetProcAddress(ipv6_dll, "getnameinfo");
2371-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2372-
FreeLibrary(ipv6_dll);
2373-
ipv6_dll = NULL;
2374-
} else
2375-
break;
2376-
}
2377-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2378-
ipv6_freeaddrinfo = freeaddrinfo_stub;
2379-
ipv6_getaddrinfo = getaddrinfo_stub;
2380-
ipv6_getnameinfo = getnameinfo_stub;
2381-
}
2382-
2383-
atexit(socket_cleanup);
2224+
2225+
atexit((void(*)(void)) WSACleanup);
23842226
initialized = 1;
23852227
}
23862228

@@ -2398,26 +2240,6 @@ struct hostent *mingw_gethostbyname(const char *host)
23982240
return gethostbyname(host);
23992241
}
24002242

2401-
void mingw_freeaddrinfo(struct addrinfo *res)
2402-
{
2403-
ipv6_freeaddrinfo(res);
2404-
}
2405-
2406-
int mingw_getaddrinfo(const char *node, const char *service,
2407-
const struct addrinfo *hints, struct addrinfo **res)
2408-
{
2409-
ensure_socket_initialization();
2410-
return ipv6_getaddrinfo(node, service, hints, res);
2411-
}
2412-
2413-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
2414-
char *host, DWORD hostlen, char *serv, DWORD servlen,
2415-
int flags)
2416-
{
2417-
ensure_socket_initialization();
2418-
return ipv6_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
2419-
}
2420-
24212243
int mingw_socket(int domain, int type, int protocol)
24222244
{
24232245
int sockfd;

compat/mingw.h

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

321-
void mingw_freeaddrinfo(struct addrinfo *res);
322-
#define freeaddrinfo mingw_freeaddrinfo
323-
324-
int mingw_getaddrinfo(const char *node, const char *service,
325-
const struct addrinfo *hints, struct addrinfo **res);
326-
#define getaddrinfo mingw_getaddrinfo
327-
328-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
329-
char *host, DWORD hostlen, char *serv, DWORD servlen,
330-
int flags);
331-
#define getnameinfo mingw_getnameinfo
332-
333321
int mingw_socket(int domain, int type, int protocol);
334322
#define socket mingw_socket
335323

0 commit comments

Comments
 (0)