|
|
| version 1.1, 2001/04/07 14:23:34 | version 1.23.8.1, 2005/08/05 13:03:02 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| Parser: socks initialization/finalization. | Parser: socks initialization/finalization. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| */ | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | static const char * const IDENT_SOCKS_C="$Date$"; |
| $Id$ | #define NO_UNISTD_H |
| */ | #include "pa_config_includes.h" |
| #ifdef WIN32 | #ifdef WIN32 |
| #include <winsock.h> | |
| #else | |
| //#include <netinet/tcp.h> | |
| //#include <arpa/nameser.h> | |
| //#include <netdb.h> | |
| //#include <signal.h> | |
| #endif | |
| #include "pa_socks.h" | |
| #include "pa_exception.h" | #include "pa_exception.h" |
| #include "pa_socks.h" | |
| #include "pa_string.h" | |
| // in cygwin: for pascal | |
| // in MSVC: for everything | |
| #include <windows.h> | |
| #ifdef CYGWIN | |
| // WSADATA | |
| #define WSADESCRIPTION_LEN 256 | |
| #define WSASYS_STATUS_LEN 128 | |
| typedef struct WSAData { | |
| WORD wVersion; | |
| WORD wHighVersion; | |
| char szDescription[WSADESCRIPTION_LEN+1]; | |
| char szSystemStatus[WSASYS_STATUS_LEN+1]; | |
| unsigned short iMaxSockets; | |
| unsigned short iMaxUdpDg; | |
| char * lpVendorInfo; | |
| } WSADATA; | |
| typedef WSADATA *LPWSADATA; | |
| /* ************************ Common stuff *********************** */ | int PASCAL WSAStartup(WORD,LPWSADATA); |
| int PASCAL WSACleanup(void); | |
| #ifdef WIN32 | #endif |
| WSADATA wsaData; | WSADATA wsaData; |
| void init_socks(Pool& pool) { | void pa_socks_init() { |
| WORD wVersionRequested; | WORD wVersionRequested; |
| int err; | int err; |
| wVersionRequested = MAKEWORD( 1, 1 ); | wVersionRequested = MAKEWORD( 1, 1 ); |
| Line 36 void init_socks(Pool& pool) { | Line 49 void init_socks(Pool& pool) { |
| if ( err != 0 ) { | if ( err != 0 ) { |
| /* Tell the user that we could not find a usable */ | /* Tell the user that we could not find a usable */ |
| /* WinSock DLL. */ | /* WinSock DLL. */ |
| PTHROW(0, 0, | throw Exception(0, |
| 0, | 0, |
| "can not WSAStartup, err=%d", | "can not WSAStartup, err=%d", |
| err); | err); |
| } | } |
| } | } |
| void done_socks() { | void pa_socks_done() { |
| /* Confirm that the WinSock DLL supports 2.2.*/ | /* Confirm that the WinSock DLL supports 2.2.*/ |
| /* Note that if the DLL supports versions greater */ | /* Note that if the DLL supports versions greater */ |
| /* than 2.2 in addition to 2.2, it will still return */ | /* than 2.2 in addition to 2.2, it will still return */ |
| Line 56 void done_socks() { | Line 69 void done_socks() { |
| } | } |
| } | } |
| const char* pa_socks_strerr(int no) { | |
| char buf[MAX_STRING]; | |
| buf[0]=0; | |
| size_t error_size=FormatMessage( | |
| FORMAT_MESSAGE_FROM_SYSTEM | | |
| FORMAT_MESSAGE_IGNORE_INSERTS, | |
| NULL, | |
| no, | |
| 0, // Default language | |
| (LPTSTR) &buf, | |
| sizeof(buf), | |
| NULL | |
| ); | |
| if(error_size>3) // ".\r\n" | |
| buf[error_size-3]=0; | |
| return buf[0]? pa_strdup(buf): "unknown error"; | |
| } | |
| int pa_socks_errno() { | |
| return WSAGetLastError(); | |
| } | |
| #else | #else |
| void init_socks(Pool& pool) {} | void pa_socks_init() {} |
| void done_socks() {} | void pa_socks_done() {} |
| const char* pa_socks_strerr(int no) { | |
| return strerror(no); | |
| } | |
| int pa_socks_errno() { | |
| return errno; | |
| } | |
| #endif | #endif |