diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-15 18:22:43 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-20 17:51:16 +1000 |
commit | 52748f68338010d28979c653ad17ca1f14d3df1a (patch) | |
tree | 08b5d11a2a4c63500967a4f2c2e869dc487e39be | |
parent | b34e416fa9d712bb4138911a2536ee709490d96b (diff) | |
download | busybox-w32-52748f68338010d28979c653ad17ca1f14d3df1a.tar.gz busybox-w32-52748f68338010d28979c653ad17ca1f14d3df1a.tar.bz2 busybox-w32-52748f68338010d28979c653ad17ca1f14d3df1a.zip |
win32: reimplement socket()
-rw-r--r-- | include/mingw.h | 6 | ||||
-rw-r--r-- | win32/net.c | 27 |
2 files changed, 32 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index d9a2fabd1..b2d73ce1b 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -174,7 +174,11 @@ NOIMPL(ioctl,int fd UNUSED_PARAM, int code UNUSED_PARAM,...); | |||
174 | */ | 174 | */ |
175 | #define hstrerror strerror | 175 | #define hstrerror strerror |
176 | 176 | ||
177 | NOIMPL(mingw_socket,int domain UNUSED_PARAM, int type UNUSED_PARAM, int protocol UNUSED_PARAM); | 177 | #ifdef CONFIG_WIN32_NET |
178 | int mingw_socket(int domain, int type, int protocol); | ||
179 | |||
180 | # define socket mingw_socket | ||
181 | #endif | ||
178 | 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); | 182 | 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); |
179 | NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); | 183 | NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); |
180 | NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM); | 184 | NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM); |
diff --git a/win32/net.c b/win32/net.c index 82c29e57c..98204b99c 100644 --- a/win32/net.c +++ b/win32/net.c | |||
@@ -18,3 +18,30 @@ void init_winsock(void) | |||
18 | WSAGetLastError()); | 18 | WSAGetLastError()); |
19 | atexit((void(*)(void)) WSACleanup); /* may conflict with other atexit? */ | 19 | atexit((void(*)(void)) WSACleanup); /* may conflict with other atexit? */ |
20 | } | 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 | } | ||