Skip to content

Commit 114a662

Browse files
committed
Merge pull request #1900 from tanushree27/remove-ipv6-fallback
[Outreachy] Removed ipv6 fallback
2 parents e6246af + 8f9735f commit 114a662

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
@@ -2083,142 +2083,10 @@ int mingw_putenv(const char *namevalue)
20832083
return result ? 0 : -1;
20842084
}
20852085

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

22232091
if (initialized)
22242092
return;
@@ -2227,35 +2095,7 @@ static void ensure_socket_initialization(void)
22272095
die("unable to initialize winsock subsystem, error %d",
22282096
WSAGetLastError());
22292097

2230-
for (name = libraries; *name; name++) {
2231-
ipv6_dll = LoadLibraryExA(*name, NULL,
2232-
LOAD_LIBRARY_SEARCH_SYSTEM32);
2233-
if (!ipv6_dll)
2234-
continue;
2235-
2236-
ipv6_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *))
2237-
GetProcAddress(ipv6_dll, "freeaddrinfo");
2238-
ipv6_getaddrinfo = (int (WSAAPI *)(const char *, const char *,
2239-
const struct addrinfo *,
2240-
struct addrinfo **))
2241-
GetProcAddress(ipv6_dll, "getaddrinfo");
2242-
ipv6_getnameinfo = (int (WSAAPI *)(const struct sockaddr *,
2243-
socklen_t, char *, DWORD,
2244-
char *, DWORD, int))
2245-
GetProcAddress(ipv6_dll, "getnameinfo");
2246-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2247-
FreeLibrary(ipv6_dll);
2248-
ipv6_dll = NULL;
2249-
} else
2250-
break;
2251-
}
2252-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
2253-
ipv6_freeaddrinfo = freeaddrinfo_stub;
2254-
ipv6_getaddrinfo = getaddrinfo_stub;
2255-
ipv6_getnameinfo = getnameinfo_stub;
2256-
}
2257-
2258-
atexit(socket_cleanup);
2098+
atexit((void(*)(void)) WSACleanup);
22592099
initialized = 1;
22602100
}
22612101

@@ -2273,26 +2113,6 @@ struct hostent *mingw_gethostbyname(const char *host)
22732113
return gethostbyname(host);
22742114
}
22752115

2276-
void mingw_freeaddrinfo(struct addrinfo *res)
2277-
{
2278-
ipv6_freeaddrinfo(res);
2279-
}
2280-
2281-
int mingw_getaddrinfo(const char *node, const char *service,
2282-
const struct addrinfo *hints, struct addrinfo **res)
2283-
{
2284-
ensure_socket_initialization();
2285-
return ipv6_getaddrinfo(node, service, hints, res);
2286-
}
2287-
2288-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
2289-
char *host, DWORD hostlen, char *serv, DWORD servlen,
2290-
int flags)
2291-
{
2292-
ensure_socket_initialization();
2293-
return ipv6_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
2294-
}
2295-
22962116
int mingw_socket(int domain, int type, int protocol)
22972117
{
22982118
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)