aboutsummaryrefslogtreecommitdiff
path: root/win32
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 /win32
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.
Diffstat (limited to 'win32')
-rw-r--r--win32/net.c41
1 files changed, 36 insertions, 5 deletions
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