diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-20 17:52:04 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-20 17:52:04 +1000 |
commit | b353bdb6c4ccab70247f04d079fd619ca25bd86a (patch) | |
tree | 0c9cdcefd0311379675cd35b9618499fdb379b95 | |
parent | 48e10caa7d284f04e45f03095d667d507529d50f (diff) | |
parent | 7b7adf5fd030387571782bd6222a62a623556961 (diff) | |
download | busybox-w32-b353bdb6c4ccab70247f04d079fd619ca25bd86a.tar.gz busybox-w32-b353bdb6c4ccab70247f04d079fd619ca25bd86a.tar.bz2 busybox-w32-b353bdb6c4ccab70247f04d079fd619ca25bd86a.zip |
Merge branch 'net' (early part)
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | include/mingw.h | 23 | ||||
-rw-r--r-- | libbb/Kbuild.src | 2 | ||||
-rw-r--r-- | networking/wget.c | 3 | ||||
-rw-r--r-- | scripts/defconfig.mingw32 | 4 | ||||
-rw-r--r-- | win32/Kbuild | 1 | ||||
-rw-r--r-- | win32/net.c | 54 |
7 files changed, 83 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index e82954fd0..221837b64 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -484,7 +484,6 @@ void xlisten(int s, int backlog) FAST_FUNC; | |||
484 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; | 484 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; |
485 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | 485 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, |
486 | socklen_t tolen) FAST_FUNC; | 486 | socklen_t tolen) FAST_FUNC; |
487 | #if !ENABLE_PLATFORM_MINGW32 | ||
488 | /* SO_REUSEADDR allows a server to rebind to an address that is already | 487 | /* SO_REUSEADDR allows a server to rebind to an address that is already |
489 | * "in use" by old connections to e.g. previous server instance which is | 488 | * "in use" by old connections to e.g. previous server instance which is |
490 | * killed or crashed. Without it bind will fail until all such connections | 489 | * killed or crashed. Without it bind will fail until all such connections |
@@ -597,7 +596,6 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags, | |||
597 | struct sockaddr *from, | 596 | struct sockaddr *from, |
598 | struct sockaddr *to, | 597 | struct sockaddr *to, |
599 | socklen_t sa_size) FAST_FUNC; | 598 | socklen_t sa_size) FAST_FUNC; |
600 | #endif | ||
601 | 599 | ||
602 | 600 | ||
603 | char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; | 601 | char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; |
diff --git a/include/mingw.h b/include/mingw.h index 85c97b702..8927b1362 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -15,6 +15,7 @@ typedef int pid_t; | |||
15 | */ | 15 | */ |
16 | static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); } | 16 | static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); } |
17 | #define ntohl git_ntohl | 17 | #define ntohl git_ntohl |
18 | int inet_aton(const char *cp, struct in_addr *inp); | ||
18 | 19 | ||
19 | /* | 20 | /* |
20 | * fcntl.h | 21 | * fcntl.h |
@@ -48,6 +49,19 @@ static inline void endgrent(void) {} | |||
48 | #define NAME_MAX 255 | 49 | #define NAME_MAX 255 |
49 | #define MAXSYMLINKS 20 | 50 | #define MAXSYMLINKS 20 |
50 | 51 | ||
52 | /* | ||
53 | * netdb.h | ||
54 | */ | ||
55 | |||
56 | typedef int sa_family_t; | ||
57 | |||
58 | /* | ||
59 | * linux/un.h | ||
60 | */ | ||
61 | struct sockaddr_un { | ||
62 | sa_family_t sun_family; | ||
63 | char sun_path[1]; /* to make compiler happy, don't bother */ | ||
64 | }; | ||
51 | 65 | ||
52 | /* | 66 | /* |
53 | * poll.h | 67 | * poll.h |
@@ -173,7 +187,13 @@ NOIMPL(ioctl,int fd UNUSED_PARAM, int code UNUSED_PARAM,...); | |||
173 | */ | 187 | */ |
174 | #define hstrerror strerror | 188 | #define hstrerror strerror |
175 | 189 | ||
176 | NOIMPL(mingw_socket,int domain UNUSED_PARAM, int type UNUSED_PARAM, int protocol UNUSED_PARAM); | 190 | #ifdef CONFIG_WIN32_NET |
191 | int mingw_socket(int domain, int type, int protocol); | ||
192 | int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz); | ||
193 | |||
194 | # define socket mingw_socket | ||
195 | # define connect mingw_connect | ||
196 | #endif | ||
177 | NOIMPL(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); | 197 | NOIMPL(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); |
178 | NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); | 198 | NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); |
179 | NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM); | 199 | NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM); |
@@ -349,3 +369,4 @@ void free_environ(char **env); | |||
349 | char **env_setenv(char **env, const char *name); | 369 | char **env_setenv(char **env, const char *name); |
350 | 370 | ||
351 | const char *get_busybox_exec_path(void); | 371 | const char *get_busybox_exec_path(void); |
372 | void init_winsock(void); | ||
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index f30fa4818..9ea3d735d 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src | |||
@@ -100,6 +100,7 @@ lib-y += wfopen.o | |||
100 | lib-y += wfopen_input.o | 100 | lib-y += wfopen_input.o |
101 | lib-y += write.o | 101 | lib-y += write.o |
102 | lib-y += xatonum.o | 102 | lib-y += xatonum.o |
103 | lib-y += xconnect.o | ||
103 | lib-y += xfunc_die.o | 104 | lib-y += xfunc_die.o |
104 | lib-y += xfuncs.o | 105 | lib-y += xfuncs.o |
105 | lib-y += xfuncs_printf.o | 106 | lib-y += xfuncs_printf.o |
@@ -118,7 +119,6 @@ lib-$(CONFIG_PLATFORM_POSIX) += read_key.o | |||
118 | lib-$(CONFIG_PLATFORM_POSIX) += safe_gethostname.o | 119 | lib-$(CONFIG_PLATFORM_POSIX) += safe_gethostname.o |
119 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o | 120 | lib-$(CONFIG_PLATFORM_POSIX) += signals.o |
120 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o | 121 | lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o |
121 | lib-$(CONFIG_PLATFORM_POSIX) += xconnect.o | ||
122 | lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o | 122 | lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o |
123 | 123 | ||
124 | lib-$(CONFIG_FEATURE_UTMP) += utmp.o | 124 | lib-$(CONFIG_FEATURE_UTMP) += utmp.o |
diff --git a/networking/wget.c b/networking/wget.c index 88bb09eb2..5b0907e11 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -579,6 +579,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
579 | #endif | 579 | #endif |
580 | 580 | ||
581 | INIT_G(); | 581 | INIT_G(); |
582 | IF_WIN32_NET(init_winsock();) | ||
582 | 583 | ||
583 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS | 584 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS |
584 | applet_long_options = wget_longopts; | 585 | applet_long_options = wget_longopts; |
@@ -737,6 +738,8 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
737 | fprintf(sfp, /* "Connection: close\r\n" */ "\r\n"); | 738 | fprintf(sfp, /* "Connection: close\r\n" */ "\r\n"); |
738 | } | 739 | } |
739 | 740 | ||
741 | fflush(sfp); | ||
742 | |||
740 | /* | 743 | /* |
741 | * Retrieve HTTP response line and check for "200" status code. | 744 | * Retrieve HTTP response line and check for "200" status code. |
742 | */ | 745 | */ |
diff --git a/scripts/defconfig.mingw32 b/scripts/defconfig.mingw32 index 89640462d..5998731bf 100644 --- a/scripts/defconfig.mingw32 +++ b/scripts/defconfig.mingw32 | |||
@@ -811,10 +811,10 @@ CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=0 | |||
811 | CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="" | 811 | CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="" |
812 | # CONFIG_UDPSVD is not set | 812 | # CONFIG_UDPSVD is not set |
813 | # CONFIG_VCONFIG is not set | 813 | # CONFIG_VCONFIG is not set |
814 | # CONFIG_WGET is not set | 814 | CONFIG_WGET=y |
815 | # CONFIG_FEATURE_WGET_STATUSBAR is not set | 815 | # CONFIG_FEATURE_WGET_STATUSBAR is not set |
816 | # CONFIG_FEATURE_WGET_AUTHENTICATION is not set | 816 | # CONFIG_FEATURE_WGET_AUTHENTICATION is not set |
817 | # CONFIG_FEATURE_WGET_LONG_OPTIONS is not set | 817 | CONFIG_FEATURE_WGET_LONG_OPTIONS=y |
818 | # CONFIG_FEATURE_WGET_TIMEOUT is not set | 818 | # CONFIG_FEATURE_WGET_TIMEOUT is not set |
819 | # CONFIG_ZCIP is not set | 819 | # CONFIG_ZCIP is not set |
820 | 820 | ||
diff --git a/win32/Kbuild b/win32/Kbuild index a4a7f32d4..bc005c23a 100644 --- a/win32/Kbuild +++ b/win32/Kbuild | |||
@@ -9,5 +9,6 @@ lib-$(CONFIG_PLATFORM_MINGW32) += fnmatch.o | |||
9 | lib-$(CONFIG_PLATFORM_MINGW32) += mingw.o | 9 | lib-$(CONFIG_PLATFORM_MINGW32) += mingw.o |
10 | lib-$(CONFIG_PLATFORM_MINGW32) += process.o | 10 | lib-$(CONFIG_PLATFORM_MINGW32) += process.o |
11 | lib-$(CONFIG_PLATFORM_MINGW32) += regex.o | 11 | lib-$(CONFIG_PLATFORM_MINGW32) += regex.o |
12 | lib-$(CONFIG_WIN32_NET) += net.o | ||
12 | lib-$(CONFIG_PLATFORM_MINGW32) += termios.o | 13 | lib-$(CONFIG_PLATFORM_MINGW32) += termios.o |
13 | lib-$(CONFIG_PLATFORM_MINGW32) += winansi.o | 14 | lib-$(CONFIG_PLATFORM_MINGW32) += winansi.o |
diff --git a/win32/net.c b/win32/net.c new file mode 100644 index 000000000..eadda6b69 --- /dev/null +++ b/win32/net.c | |||
@@ -0,0 +1,54 @@ | |||
1 | #include "libbb.h" | ||
2 | |||
3 | int inet_aton(const char *cp, struct in_addr *inp) | ||
4 | { | ||
5 | unsigned long val = inet_addr(cp); | ||
6 | |||
7 | if (val == INADDR_NONE) | ||
8 | return 0; | ||
9 | inp->S_un.S_addr = val; | ||
10 | return 1; | ||
11 | } | ||
12 | |||
13 | void init_winsock(void) | ||
14 | { | ||
15 | WSADATA wsa; | ||
16 | if (WSAStartup(MAKEWORD(2,2), &wsa)) | ||
17 | bb_error_msg_and_die("unable to initialize winsock subsystem, error %d", | ||
18 | WSAGetLastError()); | ||
19 | atexit((void(*)(void)) WSACleanup); /* may conflict with other atexit? */ | ||
20 | } | ||
21 | |||
22 | int mingw_socket(int domain, int type, int protocol) | ||
23 | { | ||
24 | int sockfd; | ||
25 | SOCKET s = WSASocket(domain, type, protocol, NULL, 0, 0); | ||
26 | if (s == INVALID_SOCKET) { | ||
27 | /* | ||
28 | * WSAGetLastError() values are regular BSD error codes | ||
29 | * biased by WSABASEERR. | ||
30 | * However, strerror() does not know about networking | ||
31 | * specific errors, which are values beginning at 38 or so. | ||
32 | * Therefore, we choose to leave the biased error code | ||
33 | * in errno so that _if_ someone looks up the code somewhere, | ||
34 | * then it is at least the number that are usually listed. | ||
35 | */ | ||
36 | errno = WSAGetLastError(); | ||
37 | return -1; | ||
38 | } | ||
39 | /* convert into a file descriptor */ | ||
40 | if ((sockfd = _open_osfhandle(s, O_RDWR|O_BINARY)) < 0) { | ||
41 | closesocket(s); | ||
42 | bb_error_msg("unable to make a socket file descriptor: %s", | ||
43 | strerror(errno)); | ||
44 | return -1; | ||
45 | } | ||
46 | return sockfd; | ||
47 | } | ||
48 | |||
49 | #undef connect | ||
50 | int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz) | ||
51 | { | ||
52 | SOCKET s = (SOCKET)_get_osfhandle(sockfd); | ||
53 | return connect(s, sa, sz); | ||
54 | } | ||