aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-06-01 08:46:17 +0100
committerRon Yorston <rmy@pobox.com>2020-06-01 08:46:17 +0100
commit5ea460a32a9882906c7ee3656b8fb0dcdbce2abc (patch)
tree3b6598f7f908ade15b3f61a815563e2c43502ac1
parent8fdbb0564ddaf0361dff8a194a0329f86738343c (diff)
downloadbusybox-w32-5ea460a32a9882906c7ee3656b8fb0dcdbce2abc.tar.gz
busybox-w32-5ea460a32a9882906c7ee3656b8fb0dcdbce2abc.tar.bz2
busybox-w32-5ea460a32a9882906c7ee3656b8fb0dcdbce2abc.zip
win32: only initialise networking if necessary
A call to initialise networking is made during start up even if the applet doesn't need it. Instead, only initialise networking when a call is made to a function that definitely requires it.
-rw-r--r--include/mingw.h8
-rw-r--r--libbb/appletlib.c4
-rw-r--r--win32/net.c41
3 files changed, 43 insertions, 10 deletions
diff --git a/include/mingw.h b/include/mingw.h
index 26f0688d7..fa8f705b0 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -229,6 +229,10 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz);
229int mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds, 229int mingw_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
230 struct timeval *timeout); 230 struct timeval *timeout);
231int mingw_getpeername(int fd, struct sockaddr *sa, socklen_t *sz); 231int mingw_getpeername(int fd, struct sockaddr *sa, socklen_t *sz);
232int mingw_gethostname(char *host, int namelen);
233int mingw_getaddrinfo(const char *node, const char *service,
234 const struct addrinfo *hints, struct addrinfo **res);
235struct hostent *mingw_gethostbyaddr(const void *addr, socklen_t len, int type);
232 236
233NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM); 237NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM);
234 238
@@ -242,6 +246,9 @@ NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len
242#define accept mingw_accept 246#define accept mingw_accept
243#define select mingw_select 247#define select mingw_select
244#define getpeername mingw_getpeername 248#define getpeername mingw_getpeername
249#define gethostname mingw_gethostname
250#define getaddrinfo mingw_getaddrinfo
251#define gethostbyaddr mingw_gethostbyaddr
245 252
246/* 253/*
247 * sys/time.h 254 * sys/time.h
@@ -502,7 +509,6 @@ void qsort_string_vector_case(char **sv, unsigned count) FAST_FUNC;
502 */ 509 */
503 510
504const char *get_busybox_exec_path(void); 511const char *get_busybox_exec_path(void);
505void init_winsock(void);
506void init_codepage(void); 512void init_codepage(void);
507 513
508int has_bat_suffix(const char *p); 514int has_bat_suffix(const char *p);
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 6e1947228..b2c85905c 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -327,10 +327,6 @@ void lbb_prepare(const char *applet
327 if (ENABLE_LOCALE_SUPPORT) 327 if (ENABLE_LOCALE_SUPPORT)
328 setlocale(LC_ALL, ""); 328 setlocale(LC_ALL, "");
329 329
330#if ENABLE_PLATFORM_MINGW32
331 init_winsock();
332#endif
333
334#if ENABLE_FEATURE_INDIVIDUAL 330#if ENABLE_FEATURE_INDIVIDUAL
335 /* Redundant for busybox (run_applet_and_exit covers that case) 331 /* Redundant for busybox (run_applet_and_exit covers that case)
336 * but needed for "individual applet" mode */ 332 * but needed for "individual applet" mode */
diff --git a/win32/net.c b/win32/net.c
index 01fa16a4e..880b807b7 100644
--- a/win32/net.c
+++ b/win32/net.c
@@ -10,19 +10,50 @@ int inet_aton(const char *cp, struct in_addr *inp)
10 return 1; 10 return 1;
11} 11}
12 12
13void init_winsock(void) 13static void init_winsock(void)
14{ 14{
15 WSADATA wsa; 15 WSADATA wsa;
16 static int initialized = 0;
17
18 if (initialized)
19 return;
20
16 if (WSAStartup(MAKEWORD(2,2), &wsa)) 21 if (WSAStartup(MAKEWORD(2,2), &wsa))
17 bb_error_msg_and_die("unable to initialize winsock subsystem, error %d", 22 bb_error_msg_and_die("WSAStartup failed, error %d", WSAGetLastError());
18 WSAGetLastError()); 23
19 atexit((void(*)(void)) WSACleanup); /* may conflict with other atexit? */ 24 atexit((void(*)(void)) WSACleanup);
25 initialized = 1;
26}
27
28#undef gethostname
29int mingw_gethostname(char *name, int namelen)
30{
31 init_winsock();
32 return gethostname(name, namelen);
33}
34
35#undef gethostbyaddr
36struct hostent *mingw_gethostbyaddr(const void *addr, socklen_t len, int type)
37{
38 init_winsock();
39 return gethostbyaddr(addr, len, type);
40}
41
42#undef getaddrinfo
43int mingw_getaddrinfo(const char *node, const char *service,
44 const struct addrinfo *hints, struct addrinfo **res)
45{
46 init_winsock();
47 return getaddrinfo(node, service, hints, res);
20} 48}
21 49
22int mingw_socket(int domain, int type, int protocol) 50int mingw_socket(int domain, int type, int protocol)
23{ 51{
24 int sockfd; 52 int sockfd;
25 SOCKET s = WSASocket(domain, type, protocol, NULL, 0, 0); 53 SOCKET s;
54
55 init_winsock();
56 s = WSASocket(domain, type, protocol, NULL, 0, 0);
26 if (s == INVALID_SOCKET) { 57 if (s == INVALID_SOCKET) {
27 /* 58 /*
28 * WSAGetLastError() values are regular BSD error codes 59 * WSAGetLastError() values are regular BSD error codes