README.md: remove reference to obsolete NO_STRDUP option
[rofl0r-rocksock.git] / rocksock_strerror.c
blob9433b904839a398134cf45a714c55f9701f7fd45
1 #include "rocksock.h"
2 #include "rocksock_internal.h"
3 #include <string.h>
4 #ifndef NO_DNS_SUPPORT
5 #include <netdb.h>
6 #endif
7 #ifdef USE_SSL
8 #include "rocksock_ssl_internal.h"
9 #endif
11 #ifdef ROCKSOCK_FILENAME
12 static const char rs_errorMap[][3] = {
13 "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7",
14 "8" , "9" , "10", "11", "12", "13", "14", "15",
15 "16", "17", "18", "19", "20", "21", "22", "23",
16 "24", "25", "26", "27"
19 #else
21 static const char* rs_errorMap[] = {
22 // RS_E_NO_ERROR,
23 "no error",
24 //RS_E_NULL,
25 "NULL pointer passed",
26 //RS_E_EXCEED_PROXY_LIMIT,
27 "exceeding maximum number of proxies",
28 //RS_E_NO_SSL,
29 "can not establish SSL connection, since library was not compiled with USE_SSL define",
30 // RS_E_NO_SOCKET
31 "socket is not set up, maybe you should call connect first",
32 // RS_E_HIT_TIMEOUT
33 "timeout reached on operation",
34 //RS_E_OUT_OF_BUFFER
35 "supplied buffer is too small",
36 // RS_E_SSL_GENERIC
37 "generic SSL error, see STDERR",
38 // RS_E_SOCKS4_NOAUTH
39 "SOCKS4 authentication not implemented",
40 // RS_E_SOCKS5_AUTH_EXCEEDSIZE
41 "maximum length for SOCKS5 servername/password/username is 255",
42 // RS_E_SOCKS4_NO_IP6
43 "SOCKS4 is not compatible with IPv6",
44 // RS_E_PROXY_UNEXPECTED_RESPONSE
45 "the proxy sent an unexpected response",
46 // RS_E_TARGETPROXY_CONNECT_FAILED
47 "could not connect to target proxy",
48 // RS_E_PROXY_AUTH_FAILED
49 "proxy authentication failed or authd not enabled",
50 //RS_E_HIT_READTIMEOUT = 14,
51 "timeout reached on read operation",
52 //RS_E_HIT_WRITETIMEOUT = 15,
53 "timeout reached on write operation",
54 //RS_E_HIT_CONNECTTIMEOUT = 16,
55 "timeout reached on connect operation",
56 //RS_E_PROXY_GENERAL_FAILURE = 17,
57 "proxy general failure",
58 //RS_E_TARGETPROXY_NET_UNREACHABLE = 18,
59 "proxy-target: net unreachable",
60 //RS_E_TARGETPROXY_HOST_UNREACHABLE = 19,
61 "proxy-target: host unreachable",
62 //RS_E_TARGETPROXY_CONN_REFUSED = 20,
63 "proxy-target: connection refused",
64 //RS_E_TARGETPROXY_TTL_EXPIRED = 21,
65 "proxy-target: TTL expired",
66 //RS_E_PROXY_COMMAND_NOT_SUPPORTED = 22,
67 "proxy: command not supported",
68 //RS_E_PROXY_ADDRESSTYPE_NOT_SUPPORTED = 23,
69 "proxy: addresstype not supported",
70 //RS_E_REMOTE_DISCONNECTED = 24,
71 "remote socket closed connection",
72 //RS_E_NO_PROXYSTORAGE = 25,
73 "no proxy storage assigned",
74 //RS_E_HOSTNAME_TOO_LONG = 26,
75 "hostname exceeds 255 chars",
76 //RS_E_INVALID_PROXY_URL = 27,
77 "invalid proxy URL string"
80 #endif
82 const char* rocksock_strerror(rocksock *sock) {
83 int error = sock->lasterror.error;
84 switch(sock->lasterror.errortype) {
85 #ifndef NO_DNS_SUPPORT
86 case RS_ET_GAI:
87 return gai_strerror(error);
88 #endif
89 case RS_ET_OWN:
90 if (error < RS_E_MAX_ERROR)
91 return rs_errorMap[error];
92 return 0;
93 case RS_ET_SYS:
94 return strerror(error);
95 #ifdef USE_SSL
96 case RS_ET_SSL: {
97 const char *tmp = rocksock_ssl_strerror(sock, error);
98 if(!tmp) return rs_errorMap[RS_E_SSL_GENERIC];
99 return tmp;
101 #endif
102 default:
103 return 0;