Skip to content

Commit 61a13cf

Browse files
committed
Merge pull request git-for-windows#1900 from tanushree27/remove-ipv6-fallback
[Outreachy] Removed ipv6 fallback
2 parents 35fc199 + 80a8fff commit 61a13cf

File tree

2 files changed

+3
-183
lines changed

2 files changed

+3
-183
lines changed

compat/mingw.c

+3-175
Original file line numberDiff line numberDiff line change
@@ -1720,142 +1720,10 @@ int mingw_putenv(const char *namevalue)
17201720
return result ? 0 : -1;
17211721
}
17221722

1723-
/*
1724-
* Note, this isn't a complete replacement for getaddrinfo. It assumes
1725-
* that service contains a numerical port, or that it is null. It
1726-
* does a simple search using gethostbyname, and returns one IPv4 host
1727-
* if one was found.
1728-
*/
1729-
static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
1730-
const struct addrinfo *hints,
1731-
struct addrinfo **res)
1732-
{
1733-
struct hostent *h = NULL;
1734-
struct addrinfo *ai;
1735-
struct sockaddr_in *sin;
1736-
1737-
if (node) {
1738-
h = gethostbyname(node);
1739-
if (!h)
1740-
return WSAGetLastError();
1741-
}
1742-
1743-
ai = xmalloc(sizeof(struct addrinfo));
1744-
*res = ai;
1745-
ai->ai_flags = 0;
1746-
ai->ai_family = AF_INET;
1747-
ai->ai_socktype = hints ? hints->ai_socktype : 0;
1748-
switch (ai->ai_socktype) {
1749-
case SOCK_STREAM:
1750-
ai->ai_protocol = IPPROTO_TCP;
1751-
break;
1752-
case SOCK_DGRAM:
1753-
ai->ai_protocol = IPPROTO_UDP;
1754-
break;
1755-
default:
1756-
ai->ai_protocol = 0;
1757-
break;
1758-
}
1759-
ai->ai_addrlen = sizeof(struct sockaddr_in);
1760-
if (hints && (hints->ai_flags & AI_CANONNAME))
1761-
ai->ai_canonname = h ? xstrdup(h->h_name) : NULL;
1762-
else
1763-
ai->ai_canonname = NULL;
1764-
1765-
sin = xcalloc(1, ai->ai_addrlen);
1766-
sin->sin_family = AF_INET;
1767-
/* Note: getaddrinfo is supposed to allow service to be a string,
1768-
* which should be looked up using getservbyname. This is
1769-
* currently not implemented */
1770-
if (service)
1771-
sin->sin_port = htons(atoi(service));
1772-
if (h)
1773-
sin->sin_addr = *(struct in_addr *)h->h_addr;
1774-
else if (hints && (hints->ai_flags & AI_PASSIVE))
1775-
sin->sin_addr.s_addr = INADDR_ANY;
1776-
else
1777-
sin->sin_addr.s_addr = INADDR_LOOPBACK;
1778-
ai->ai_addr = (struct sockaddr *)sin;
1779-
ai->ai_next = NULL;
1780-
return 0;
1781-
}
1782-
1783-
static void WSAAPI freeaddrinfo_stub(struct addrinfo *res)
1784-
{
1785-
free(res->ai_canonname);
1786-
free(res->ai_addr);
1787-
free(res);
1788-
}
1789-
1790-
static int WSAAPI getnameinfo_stub(const struct sockaddr *sa, socklen_t salen,
1791-
char *host, DWORD hostlen,
1792-
char *serv, DWORD servlen, int flags)
1793-
{
1794-
const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
1795-
if (sa->sa_family != AF_INET)
1796-
return EAI_FAMILY;
1797-
if (!host && !serv)
1798-
return EAI_NONAME;
1799-
1800-
if (host && hostlen > 0) {
1801-
struct hostent *ent = NULL;
1802-
if (!(flags & NI_NUMERICHOST))
1803-
ent = gethostbyaddr((const char *)&sin->sin_addr,
1804-
sizeof(sin->sin_addr), AF_INET);
1805-
1806-
if (ent)
1807-
snprintf(host, hostlen, "%s", ent->h_name);
1808-
else if (flags & NI_NAMEREQD)
1809-
return EAI_NONAME;
1810-
else
1811-
snprintf(host, hostlen, "%s", inet_ntoa(sin->sin_addr));
1812-
}
1813-
1814-
if (serv && servlen > 0) {
1815-
struct servent *ent = NULL;
1816-
if (!(flags & NI_NUMERICSERV))
1817-
ent = getservbyport(sin->sin_port,
1818-
flags & NI_DGRAM ? "udp" : "tcp");
1819-
1820-
if (ent)
1821-
snprintf(serv, servlen, "%s", ent->s_name);
1822-
else
1823-
snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
1824-
}
1825-
1826-
return 0;
1827-
}
1828-
1829-
static HMODULE ipv6_dll = NULL;
1830-
static void (WSAAPI *ipv6_freeaddrinfo)(struct addrinfo *res);
1831-
static int (WSAAPI *ipv6_getaddrinfo)(const char *node, const char *service,
1832-
const struct addrinfo *hints,
1833-
struct addrinfo **res);
1834-
static int (WSAAPI *ipv6_getnameinfo)(const struct sockaddr *sa, socklen_t salen,
1835-
char *host, DWORD hostlen,
1836-
char *serv, DWORD servlen, int flags);
1837-
/*
1838-
* gai_strerror is an inline function in the ws2tcpip.h header, so we
1839-
* don't need to try to load that one dynamically.
1840-
*/
1841-
1842-
static void socket_cleanup(void)
1843-
{
1844-
WSACleanup();
1845-
if (ipv6_dll)
1846-
FreeLibrary(ipv6_dll);
1847-
ipv6_dll = NULL;
1848-
ipv6_freeaddrinfo = freeaddrinfo_stub;
1849-
ipv6_getaddrinfo = getaddrinfo_stub;
1850-
ipv6_getnameinfo = getnameinfo_stub;
1851-
}
1852-
18531723
static void ensure_socket_initialization(void)
18541724
{
18551725
WSADATA wsa;
18561726
static int initialized = 0;
1857-
const char *libraries[] = { "ws2_32.dll", "wship6.dll", NULL };
1858-
const char **name;
18591727

18601728
if (initialized)
18611729
return;
@@ -1864,35 +1732,7 @@ static void ensure_socket_initialization(void)
18641732
die("unable to initialize winsock subsystem, error %d",
18651733
WSAGetLastError());
18661734

1867-
for (name = libraries; *name; name++) {
1868-
ipv6_dll = LoadLibraryExA(*name, NULL,
1869-
LOAD_LIBRARY_SEARCH_SYSTEM32);
1870-
if (!ipv6_dll)
1871-
continue;
1872-
1873-
ipv6_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *))
1874-
GetProcAddress(ipv6_dll, "freeaddrinfo");
1875-
ipv6_getaddrinfo = (int (WSAAPI *)(const char *, const char *,
1876-
const struct addrinfo *,
1877-
struct addrinfo **))
1878-
GetProcAddress(ipv6_dll, "getaddrinfo");
1879-
ipv6_getnameinfo = (int (WSAAPI *)(const struct sockaddr *,
1880-
socklen_t, char *, DWORD,
1881-
char *, DWORD, int))
1882-
GetProcAddress(ipv6_dll, "getnameinfo");
1883-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
1884-
FreeLibrary(ipv6_dll);
1885-
ipv6_dll = NULL;
1886-
} else
1887-
break;
1888-
}
1889-
if (!ipv6_freeaddrinfo || !ipv6_getaddrinfo || !ipv6_getnameinfo) {
1890-
ipv6_freeaddrinfo = freeaddrinfo_stub;
1891-
ipv6_getaddrinfo = getaddrinfo_stub;
1892-
ipv6_getnameinfo = getnameinfo_stub;
1893-
}
1894-
1895-
atexit(socket_cleanup);
1735+
atexit((void(*)(void)) WSACleanup);
18961736
initialized = 1;
18971737
}
18981738

@@ -1910,24 +1750,12 @@ struct hostent *mingw_gethostbyname(const char *host)
19101750
return gethostbyname(host);
19111751
}
19121752

1913-
void mingw_freeaddrinfo(struct addrinfo *res)
1914-
{
1915-
ipv6_freeaddrinfo(res);
1916-
}
1917-
1753+
#undef getaddrinfo
19181754
int mingw_getaddrinfo(const char *node, const char *service,
19191755
const struct addrinfo *hints, struct addrinfo **res)
19201756
{
19211757
ensure_socket_initialization();
1922-
return ipv6_getaddrinfo(node, service, hints, res);
1923-
}
1924-
1925-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
1926-
char *host, DWORD hostlen, char *serv, DWORD servlen,
1927-
int flags)
1928-
{
1929-
ensure_socket_initialization();
1930-
return ipv6_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
1758+
return getaddrinfo(node, service, hints, res);
19311759
}
19321760

19331761
int mingw_socket(int domain, int type, int protocol)

compat/mingw.h

-8
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,10 @@ int mingw_gethostname(char *host, int namelen);
296296
struct hostent *mingw_gethostbyname(const char *host);
297297
#define gethostbyname mingw_gethostbyname
298298

299-
void mingw_freeaddrinfo(struct addrinfo *res);
300-
#define freeaddrinfo mingw_freeaddrinfo
301-
302299
int mingw_getaddrinfo(const char *node, const char *service,
303300
const struct addrinfo *hints, struct addrinfo **res);
304301
#define getaddrinfo mingw_getaddrinfo
305302

306-
int mingw_getnameinfo(const struct sockaddr *sa, socklen_t salen,
307-
char *host, DWORD hostlen, char *serv, DWORD servlen,
308-
int flags);
309-
#define getnameinfo mingw_getnameinfo
310-
311303
int mingw_socket(int domain, int type, int protocol);
312304
#define socket mingw_socket
313305

0 commit comments

Comments
 (0)