diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-27 20:15:49 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2009-04-28 14:31:59 +1000 |
commit | 087b73d87ebab807ba38e2d543756ac2bc17becc (patch) | |
tree | 46dcd5e936d72cc56b1af15c5be5c2c3696b412b | |
parent | 1756cc5943aa545f2f18fff60d56ad0886ef6145 (diff) | |
download | busybox-w32-087b73d87ebab807ba38e2d543756ac2bc17becc.tar.gz busybox-w32-087b73d87ebab807ba38e2d543756ac2bc17becc.tar.bz2 busybox-w32-087b73d87ebab807ba38e2d543756ac2bc17becc.zip |
libbb/xconnect: initialize winsock before using it
-rw-r--r-- | libbb/Kbuild | 2 | ||||
-rw-r--r-- | libbb/mingw.c | 20 | ||||
-rw-r--r-- | libbb/xconnect.c | 8 |
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 | |||
22 | lib-y += speed_table.o | 22 | lib-y += speed_table.o |
23 | lib-y += vfork_daemon_rexec.o | 23 | lib-y += vfork_daemon_rexec.o |
24 | lib-y += vinfo_msg.o | 24 | lib-y += vinfo_msg.o |
25 | lib-y += xconnect.o | ||
26 | lib-y += xgethostbyname.o | 25 | lib-y += xgethostbyname.o |
27 | endif | 26 | endif |
28 | 27 | ||
@@ -99,6 +98,7 @@ lib-y += wfopen_input.o | |||
99 | lib-y += xatonum.o | 98 | lib-y += xatonum.o |
100 | lib-y += xfuncs.o | 99 | lib-y += xfuncs.o |
101 | lib-y += xgetcwd.o | 100 | lib-y += xgetcwd.o |
101 | lib-y += xconnect.o | ||
102 | lib-y += xreadlink.o | 102 | lib-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 | ||
1000 | void 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 |
1002 | struct hostent *mingw_gethostbyname(const char *host) | 1015 | struct 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 | ||
12 | int setsockopt_reuseaddr(int fd) | 19 | int 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); |