Skip to content

Commit 26dcaa1

Browse files
committed
Merge pull request #1900 from tanushree27/remove-ipv6-fallback
[Outreachy] Removed ipv6 fallback
2 parents 140e559 + c495a46 commit 26dcaa1

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
@@ -2113,142 +2113,10 @@ int mingw_putenv(const char *namevalue)
21132113
return result ? 0 : -1;
21142114
}
21152115

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

22532121
if (initialized)
22542122
return;
@@ -2257,35 +2125,7 @@ static void ensure_socket_initialization(void)
22572125
die("unable to initialize winsock subsystem, error %d",
22582126
WSAGetLastError());
22592127

2260-
for (name = libraries; *name; name++) {
2261-
ipv6_dll = LoadLibraryExA(*name, NULL,
2262-
LOAD_LIBRARY_SEARCH_SYSTEM32);
2263-
if (!ipv6_dll)
2264-
continue;
2265-
2266-
ipv6_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *))
2267-
GetProcAddress(ipv6_dll, "freeaddrinfo");
2268-
ipv6_getaddrinfo = (int (WSAAPI *)(const char *, const char *,
2269-
const struct addrinfo *,
2270-
struct addrinfo **))
2271-
GetProcAddress(ipv6_dll, "getaddrinfo");
2272-
ipv6_getnameinfo = (int (WSAAPI *)(const struct sockaddr *,
2273-
socklen_t, char *, DWORD,
2274-
char *, DWORD, int))
2275-
GetProcAddress(ipv6_dll, "getnameinfo");
2276-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2277-
FreeLibrary(ipv6_dll);
2278-
ipv6_dll = NULL;
2279-
} else
2280-
break;
2281-
}
2282-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2283-
ipv6_freeaddrinfo = freeaddrinfo_stub;
2284-
ipv6_getaddrinfo = getaddrinfo_stub;
2285-
ipv6_getnameinfo = getnameinfo_stub;
2286-
}
2287-
2288-
atexit(socket_cleanup);
2128+
atexit((void(*)(void)) WSACleanup);
22892129
initialized = 1;
22902130
}
22912131

@@ -2303,26 +2143,6 @@ struct hostent *mingw_gethostbyname(const char *host)
23032143
return gethostbyname(host);
23042144
}
23052145

2306-
void mingw_freeaddrinfo(struct addrinfo *res)
2307-
{
2308-
ipv6_freeaddrinfo(res);
2309-
}
2310-
2311-
int mingw_getaddrinfo(const char *node, const char *service,
2312-
const struct addrinfo *hints, struct addrinfo **res)
2313-
{
2314-
ensure_socket_initialization();
2315-
return ipv6_getaddrinfo(node, service, hints, res);
2316-
}
2317-
2318-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
2319-
char *host, DWORD hostlen, char *serv, DWORD servlen,
2320-
int flags)
2321-
{
2322-
ensure_socket_initialization();
2323-
return ipv6_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
2324-
}
2325-
23262146
int mingw_socket(int domain, int type, int protocol)
23272147
{
23282148
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)