aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-27 20:15:49 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-28 14:31:59 +1000
commit087b73d87ebab807ba38e2d543756ac2bc17becc (patch)
tree46dcd5e936d72cc56b1af15c5be5c2c3696b412b
parent1756cc5943aa545f2f18fff60d56ad0886ef6145 (diff)
downloadbusybox-w32-087b73d87ebab807ba38e2d543756ac2bc17becc.tar.gz
busybox-w32-087b73d87ebab807ba38e2d543756ac2bc17becc.tar.bz2
busybox-w32-087b73d87ebab807ba38e2d543756ac2bc17becc.zip
libbb/xconnect: initialize winsock before using it
-rw-r--r--libbb/Kbuild2
-rw-r--r--libbb/mingw.c20
-rw-r--r--libbb/xconnect.c8
3 files changed, 23 insertions, 7 deletions
diff --git a/libbb/Kbuild b/libbb/Kbuild
index dca58d6f7..e335a95dc 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -22,7 +22,6 @@ lib-y += setup_environment.o
22lib-y += speed_table.o 22lib-y += speed_table.o
23lib-y += vfork_daemon_rexec.o 23lib-y += vfork_daemon_rexec.o
24lib-y += vinfo_msg.o 24lib-y += vinfo_msg.o
25lib-y += xconnect.o
26lib-y += xgethostbyname.o 25lib-y += xgethostbyname.o
27endif 26endif
28 27
@@ -99,6 +98,7 @@ lib-y += wfopen_input.o
99lib-y += xatonum.o 98lib-y += xatonum.o
100lib-y += xfuncs.o 99lib-y += xfuncs.o
101lib-y += xgetcwd.o 100lib-y += xgetcwd.o
101lib-y += xconnect.o
102lib-y += xreadlink.o 102lib-y += xreadlink.o
103 103
104# conditionally compiled objects: 104# conditionally compiled objects:
diff --git a/libbb/mingw.c b/libbb/mingw.c
index 4b267e2ba..1293dc7eb 100644
--- a/libbb/mingw.c
+++ b/libbb/mingw.c
@@ -997,16 +997,24 @@ char **env_setenv(char **env, const char *name)
997 return env; 997 return env;
998} 998}
999 999
1000void winsock_init()
1001{
1002 static int init = 0;
1003 if (!init) {
1004 WSADATA wsa;
1005 if (WSAStartup(MAKEWORD(2,2), &wsa))
1006 die("unable to initialize winsock subsystem, error %d",
1007 WSAGetLastError());
1008 atexit((void(*)(void)) WSACleanup);
1009 init = 1;
1010 }
1011}
1012
1000/* this is the first function to call into WS_32; initialize it */ 1013/* this is the first function to call into WS_32; initialize it */
1001#undef gethostbyname 1014#undef gethostbyname
1002struct hostent *mingw_gethostbyname(const char *host) 1015struct hostent *mingw_gethostbyname(const char *host)
1003{ 1016{
1004 WSADATA wsa; 1017 winsock_init();
1005
1006 if (WSAStartup(MAKEWORD(2,2), &wsa))
1007 die("unable to initialize winsock subsystem, error %d",
1008 WSAGetLastError());
1009 atexit((void(*)(void)) WSACleanup);
1010 return gethostbyname(host); 1018 return gethostbyname(host);
1011} 1019}
1012 1020
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index e7d510678..6e9b29298 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -6,7 +6,14 @@
6 * 6 *
7 */ 7 */
8 8
9#ifdef __MINGW32__
10#define WINVER 0x0501
11#include <winsock2.h>
12#include <ws2tcpip.h>
13#undef s_addr
14#else
9#include <netinet/in.h> 15#include <netinet/in.h>
16#endif
10#include "libbb.h" 17#include "libbb.h"
11 18
12int setsockopt_reuseaddr(int fd) 19int setsockopt_reuseaddr(int fd)
@@ -162,6 +169,7 @@ USE_FEATURE_IPV6(sa_family_t af,)
162 * for each possible socket type (tcp,udp,raw...): */ 169 * for each possible socket type (tcp,udp,raw...): */
163 hint.ai_socktype = SOCK_STREAM; 170 hint.ai_socktype = SOCK_STREAM;
164 hint.ai_flags = ai_flags & ~DIE_ON_ERROR; 171 hint.ai_flags = ai_flags & ~DIE_ON_ERROR;
172 winsock_init();
165 rc = getaddrinfo(host, NULL, &hint, &result); 173 rc = getaddrinfo(host, NULL, &hint, &result);
166 if (rc || !result) { 174 if (rc || !result) {
167 bb_error_msg("bad address '%s'", org_host); 175 bb_error_msg("bad address '%s'", org_host);