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 /win32 | |
parent | b34e416fa9d712bb4138911a2536ee709490d96b (diff) | |
download | busybox-w32-52748f68338010d28979c653ad17ca1f14d3df1a.tar.gz busybox-w32-52748f68338010d28979c653ad17ca1f14d3df1a.tar.bz2 busybox-w32-52748f68338010d28979c653ad17ca1f14d3df1a.zip |
win32: reimplement socket()
Diffstat (limited to 'win32')
-rw-r--r-- | win32/net.c | 27 |
1 files changed, 27 insertions, 0 deletions
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 | } | ||