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 /win32 | |
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)
Diffstat (limited to 'win32')
-rw-r--r-- | win32/Kbuild | 1 | ||||
-rw-r--r-- | win32/net.c | 54 |
2 files changed, 55 insertions, 0 deletions
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 | } | ||