From 52748f68338010d28979c653ad17ca1f14d3df1a Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 15 Sep 2010 18:22:43 +1000 Subject: win32: reimplement socket() --- win32/net.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'win32') 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) WSAGetLastError()); atexit((void(*)(void)) WSACleanup); /* may conflict with other atexit? */ } + +int mingw_socket(int domain, int type, int protocol) +{ + int sockfd; + SOCKET s = WSASocket(domain, type, protocol, NULL, 0, 0); + if (s == INVALID_SOCKET) { + /* + * WSAGetLastError() values are regular BSD error codes + * biased by WSABASEERR. + * However, strerror() does not know about networking + * specific errors, which are values beginning at 38 or so. + * Therefore, we choose to leave the biased error code + * in errno so that _if_ someone looks up the code somewhere, + * then it is at least the number that are usually listed. + */ + errno = WSAGetLastError(); + return -1; + } + /* convert into a file descriptor */ + if ((sockfd = _open_osfhandle(s, O_RDWR|O_BINARY)) < 0) { + closesocket(s); + bb_error_msg("unable to make a socket file descriptor: %s", + strerror(errno)); + return -1; + } + return sockfd; +} -- cgit v1.2.3-55-g6feb