📄 common.h
字号:
#define SASSERT(expression) \do { \ if (!(expression)) \ SERR(expression); \} while (lintnoloop_common_h)#define SASSERTX(expression) \do { \ if (!(expression)) \ SERRX(expression); \} while (lintnoloop_common_h)/* * wrappers around err()/errx()/warn()/warnx() for more consistent error * messages. * "failure" is the value that was wrong and which caused the internal error. */#define SERR(failure) \do { \ SWARN(failure); \ abort(); \} while (lintnoloop_common_h)#define SERRX(failure) \do { \ SWARNX(failure); \ abort(); \} while (lintnoloop_common_h)#define SWARN(failure) \ swarn(INTERNAL_ERROR, \ __FILE__, __LINE__, (long int)(failure), rcsid)#define SWARNX(failure) \ swarnx(INTERNAL_ERROR, \ __FILE__, __LINE__, (long int)(failure), rcsid)#define ERR(failure) \do { \ warn(INTERNAL_ERROR, __FILE__, __LINE__, \ (long int)(failure), rcsid); \ abort(); \} while (p)#define ERRX(failure) \do { \ warnx(INTERNAL_ERROR, __FILE__, __LINE__, \ (long int)(failure), rcsid); \ abort(); \} while (lintnoloop_common_h)#define WARN(failure) \ warn(INTERNAL_ERROR, __FILE__, __LINE__, (long int)(failure), rcsid)#define WARNX(failure) \ warnx(INTERNAL_ERROR, __FILE__, __LINE__, (long int)(failure), rcsid)#define ERRORMSG(failure) \ error_msg(LOG_HIGH, INTERNAL_ERROR, __FILE__, __LINE__, (long int)(failure),\ rcsid)/* the size of a udp header "packet" (no padding) */#define PACKETSIZE_UDP(packet) ( \ sizeof((packet)->flag) + sizeof((packet)->frag) \ + sizeof((packet)->host.atype) + sizeof((packet)->host.port) \ + (ADDRESSIZE_V5(packet)))/* * returns the length of the current address field in socks packet "packet". * "packet" can be one of pointer to response_t, request_t or udpheader_t. */#define ADDRESSIZE(packet) ( \ ((packet)->version == SOCKS_V4 ? \ (ADDRESSIZE_V4(packet)) : (ADDRESSIZE_V5(packet))))/* * version specifics */#define ADDRESSIZE_V5(packet) ( \ (packet)->host.atype == SOCKS_ADDR_IPV4 ? \ sizeof((packet)->host.addr.ipv4) :(packet)->host.atype == SOCKS_ADDR_IPV6 ? \ sizeof((packet)->host.addr.ipv6) : (strlen((packet)->host.addr.domain) + 1))#define ADDRESSIZE_V4(packet) ( \ (packet)->atype == SOCKS_ADDR_IPV4 ? \ sizeof((packet)->addr.ipv4) : (strlen((packet)->addr.host) + 1))/* * This is for Rgethostbyname() support for clients without access to * dns. * FAKEIP_START is the first address in the range of "fake" ip addresses, * FAKEIP_END is the last. * There can thus be FAKEIP_END - FAKEIP_START number of fake ip addresses * supported per program. * * INADDR_NONE and INADDR_ANY may not be part of the range. */#define FAKEIP_START 0x00000001#define FAKEIP_END 0x000000ff#define SOCKS_V4 4#define SOCKS_V4REPLY_VERSION 0#define SOCKS_V5 5#define MSPROXY_V2 2/* subnegotiation. */#define SOCKS_UNAMEVERSION 1/* authentication METHOD values. */#define AUTHMETHOD_NONE 0#define AUTHMETHOD_NONEs "none"#define AUTHMETHOD_GSSAPI 1#define AUTHMETHOD_GSSAPIs "gssapi"#define AUTHMETHOD_UNAME 2#define AUTHMETHOD_UNAMEs "username"/* X'03' to X'7F' IANA ASSIGNED *//* X'80' to X'FE' RESERVED FOR PRIVATE METHODS */#define AUTHMETHOD_NOACCEPT 255#define AUTHMETHOD_NOACCEPTs "no acceptable method"/* not standard methods, must be > 255. */#define AUTHMETHOD_RFC931 256#define AUTHMETHOD_RFC931s "rfc931"#define AUTHMETHOD_MAX (AUTHMETHOD_RFC931 + 1)/* * Response commands/codes */#define SOCKS_CONNECT 1#define SOCKS_CONNECTs "connect"#define SOCKS_BIND 2#define SOCKS_BINDs "bind"#define SOCKS_UDPASSOCIATE 3#define SOCKS_UDPASSOCIATEs "udpassociate"/* pseudo commands */#define SOCKS_COMMANDEND 0xff#define SOCKS_BINDREPLY (SOCKS_COMMANDEND + 1)#define SOCKS_BINDREPLYs "bindreply"#define SOCKS_UDPREPLY (SOCKS_BINDREPLY + 1)#define SOCKS_UDPREPLYs "udpreply"/* misc stuff */#define SOCKS_ACCEPT (SOCKS_UDPREPLY + 1)#define SOCKS_ACCEPTs "accept"#define SOCKS_DISCONNECT (SOCKS_ACCEPT + 1)#define SOCKS_DISCONNECTs "disconnect"/* address types */#define SOCKS_ADDR_IPV4 0x01#define SOCKS_ADDR_DOMAIN 0x03#define SOCKS_ADDR_IPV6 0x04/* reply field values */#define SOCKS_SUCCESS 0x00#define SOCKS_FAILURE 0x01#define SOCKS_NOTALLOWED 0x02#define SOCKS_NETUNREACH 0x03#define SOCKS_HOSTUNREACH 0x04#define SOCKS_CONNREFUSED 0x05#define SOCKS_TTLEXPIRED 0x06#define SOCKS_CMD_UNSUPP 0x07#define SOCKS_ADDR_UNSUPP 0x08#define SOCKS_INVALID_ADDRESS 0x09/* version 4 codes. */#define SOCKSV4_SUCCESS 90#define SOCKSV4_FAIL 91#define SOCKSV4_NO_IDENTD 92#define SOCKSV4_BAD_ID 93#define MSPROXY_PINGINTERVAL (6 * 60)#define MSPROXY_SUCCESS 0#define MSPROXY_FAILURE 1#define MSPROXY_NOTALLOWED 2#define MSPROXY_MINLENGTH 172 /* minimum length of packet. */#define MSPROXY_VERSION 0x00010200 /* perhaps? *//* errors */#define MSPROXY_ADDRINUSE 0x0701#define MSPROXY_BIND_AUTHFAILED 0x0804 /* auth failed for connect. */#define MSPROXY_CONNECT_AUTHFAILED 0x081e /* auth failed for bind. */#define MSPROXY_CONNREFUSED 0x4 /* low 12 bits seem to vary. *//* * Server seems to ignore loworder bits of a 0x47?? command, so take them * for our own use. */#define MSPROXY_HELLO 0x0500 /* packet 1 from client. */#define MSPROXY_HELLO_ACK 0x1000 /* packet 1 from server. */#define MSPROXY_USERINFO 0x1000 /* packet 2 from client. */#define MSPROXY_USERINFO_ACK 0x0400 /* packet 2 from server. */#define MSPROXY_SOMETHING 0x4700 /* packet 3 from client. */#define MSPROXY_SOMETHING_1_ACK 0x4714 /* packet 3 from server. */#define MSPROXY_SOMETHING_2 0x4701 /* packet 4 from client. */#define MSPROXY_SOMETHING_2_ACK 0x4715 /* packet 4 from server, high 8 bits seem to vary. */#define MSPROXY_SOMETHING_2_ACK2 0x4716 /* could be this too... dunno. */#define MSPROXY_RESOLVE 0x070d /* resolve request from client. */#define MSPROXY_RESOLVE_ACK 0x070f /* resolved info from server. */#define MSPROXY_BIND 0x0704 /* bind request. */#define MSPROXY_BIND_ACK 0x0706 /* bind request accepted. */#define MSPROXY_BIND2 0x0707 /* dunno. */#define MSPROXY_BIND2_ACK 0x0708 /* dunno. */#define MSPROXY_BIND2 0x0707 /* dunno. */#define MSPROXY_BIND2_ACK 0x0708 /* dunno. */#define MSPROXY_LISTEN 0x0406 /* listen() performed(?) */#define MSPROXY_BINDINFO 0x0709 /* info about client server accepted*/#define MSPROXY_BINDINFO_ACK 0x070a /* we got the info(?) */#define MSPROXY_CONNECT 0x071e /* connect request. */#define MSPROXY_CONNECT_ACK 0x0703 /* connect request accepted. */#define MSPROXY_UDPASSOCIATE 0x0705 /* udp associate request. */#define MSPROXY_UDPASSOCIATE_ACK 0x0706 /* udp associate request accepted. */#define MSPROXY_CONNECTED 0x042c /* client connected to server? */#define MSPROXY_SESSIONEND 0x251e /* maybe... *//* flag _bits_ */#define SOCKS_INTERFACEREQUEST 0x01#define SOCKS_USECLIENTPORT 0x04/* subcommands */#define SOCKS_INTERFACEDATA 0x01#define SOCKS_TCP 1#define SOCKS_UDP 2#define SOCKS_RECV 0#define SOCKS_SEND 1#if 0/* where is this from? (michaels) */#if defined(__alpha__)typedef unsigned int u_int32;#elsetypedef unsigned long u_int32;#endif#endif/* offsets into authentication packet */#define AUTH_VERSION 0 /* version of method packet. *//* request */#define AUTH_NMETHODS 1 /* number of methods to offer. */#define AUTH_METHODS 2 /* start of methods to offer. *//* reply */#define AUTH_VERSION 0 /* offset for version in reply. */#define AUTH_METHOD 1 /* offset for selected method in reply. *//* offsets into username/password negotiation packet */#define UNAME_VERSION 0#define UNAME_STATUS 1/* XXX no ivp6 support currently. */#define SOCKS_IPV6_ALEN 16#if !defined(SOCKSLIBRARY_DYNAMIC)#define sys_accept(s, addr, addrlen) accept(s, addr, addrlen)#define sys_bind(s, name, namelen) bind(s, name, namelen)#define sys_connect(s, name, namelen) connect(s, name, namelen)#define sys_bindresvport(sd, sin) bindresvport(sd, sin)#define sys_gethostbyname(name) gethostbyname(name)#define sys_gethostbyname2(name, af) gethostbyname2(name, af)#define sys_getpeername(s, name, namelen) getpeername(s, name, namelen)#define sys_getsockname(s, name, namelen) getsockname(s, name, namelen)#define sys_recvfrom(s, buf, len, flags, from, fromlen) \ recvfrom(s, buf, len, flags, from, fromlen)#define sys_rresvport(port) rresvport(port)#define sys_sendto(s, msg, len, flags, to, tolen) \ sendto(s, msg, len, flags, to, tolen)#endifenum operator_t { none = 0, eq, neq, ge, le, gt, lt, range };struct compat_t { unsigned reuseaddr:1; /* set SO_REUSEADDR? */ unsigned sameport:1; /* always try to use same port as client? */ unsigned :0;};struct logtype_t { int type; /* type of logging (where to). */ FILE **fpv; /* if logging is to file, this is the open file.*/ int fpc; int *fplockv; /* locking of logfiles. */ int facility; /* if logging to syslog, this is the facility. */};/* extensions supported by us. */struct extension_t { unsigned bind:1; /* use bind extension? */ unsigned :0;};/* the address part of a socks packet */union socksaddr_t { struct in_addr ipv4; char ipv6[SOCKS_IPV6_ALEN]; char domain[MAXHOSTNAMELEN]; /* _always_ stored as C string. */};/* the hostspecific part of misc. things */struct sockshost_t { unsigned char atype; union socksaddr_t addr; in_port_t port;};struct msproxy_request_t { char username[MAXNAMELEN]; char unknown[MAXNAMELEN]; char executable[MAXNAMELEN]; char clienthost[MAXHOSTNAMELEN]; int32_t clientid; /* 1-4 */ int32_t magic25; /* 5-8 */ int32_t serverid; /* 9-12 */ unsigned char serverack; /* 13: ack of last server packet */ char pad10[3]; /* 14-16 */ unsigned char sequence; /* 17: sequence # of this packet. */ char pad11[7]; /* 18-24 */ char RWSP[4]; /* 25-28: 0x52,0x57,0x53,0x50 */ char pad15[8]; /* 29-36 */ int16_t command; /* 37-38 */ /* packet specifics start at 39. */ union { struct { char pad1[18]; /* 39-56 */ int16_t magic3; /* 57-58 */ char pad3[114]; /* 59-172 */ int16_t magic5; /* 173-174: 0x4b, 0x00 */ char pad5[2]; /* 175-176 */ int16_t magic10; /* 177-178: 0x14, 0x00 */ char pad6[2]; /* 179-180 */ int16_t magic15; /* 181-182: 0x04, 0x00 */ char pad10[6]; /* 183-188 */ int16_t magic20; /* 189-190: 0x57, 0x04 */ int16_t magic25; /* 191-192: 0x00, 0x04 */ int16_t magic30; /* 193-194: 0x01, 0x00 */ char pad20[2]; /* 195-196: 0x4a, 0x02 */ int16_t magic35; /* 197-198: 0x4a, 0x02 */ char pad30[10]; /* 199-208 */ int16_t magic40; /* 209-210: 0x30, 0x00 */ char pad40[2]; /* 211-212 */ int16_t magic45; /* 213-214: 0x44, 0x00 */ char pad45[2]; /* 215-216 */ int16_t magic50; /* 217-218: 0x39, 0x00 */ char pad50[2]; /* 219-220 */ } _1; struct { char pad1[18]; /* 39-56 */ int16_t magic3; /* 57-58 */ char pad3[114]; /* 59-172 */ int16_t magic5; /* 173-174: 0x00, 0x4b */ char pad5[2]; /* 175-176 */ int16_t magic10; /* 177-178: 0x14, 0x00 */ char pad10[2]; /* 179-180 */ int16_t magic15; /* 181-182: 0x04, 0x00 */ char pad15[6]; /* 183-188 */ int16_t magic20; /* 189-190: 0x57, 0x04 */ int16_t magic25; /* 191-192: 0x00, 0x04 */ int16_t magic30; /* 193-194: 0x01, 0x00 */ char pad20[2]; /* 195-196 */ int16_t magic35; /* 197-198: 0x04, 0x00 */ char pad25[10]; /* 199-208 */ int16_t magic50; /* 209-210: 0x30, 0x00 */ char pad50[2]; /* 211-212 */ int16_t magic55; /* 213-214: 0x44, 0x00 */ char pad55[2]; /* 215-216 */ int16_t magic60; /* 217-218: 0x39, 0x00 */ } _2; struct { char pad1[4]; /* 39-42 */ int16_t magic2; /* 43-44 */ char pad10[12]; /* 45-56 */ in_addr_t bindaddr; /* 57-60: address to bind. */ in_port_t bindport; /* 61-62: port to bind. */ char pad15[2]; /* 63-64 */ int16_t magic3; /* 65-66 */ in_port_t boundport; /* 67-68 */ char pad20[104]; /* 69-172 */ char NTLMSSP[sizeof("NTLMSSP")]; /* 173-180: "NTLMSSP" */ int16_t magic5; /* 181-182: 0x01, 0x00 */ char pad25[2]; /* 183-184 */ int16_t magic10; /* 185-186: 0x96, 0x82 */ int16_t magic15; /* 187-188: 0x08, 0x00 */ int16_t magic20; /* 189-190: 0x28, 0x00 */ char pad30[2]; /* 191-192 */ int16_t magic25; /* 193-194: 0x96, 0x82 */ int16_t magic30; /* 195-196: 0x01, 0x00 */ char pad40[12]; /* 197-208 */ int16_t magic50; /* 209-210: 0x30, 0x00 */ char pad50[6]; /* 211-216 */ int16_t magic55; /* 217-218: 0x30, 0x00 */ char pad55[2]; /* 219-220 */ } _3; struct { char pad1[4]; /* 39-42 */ int16_t magic1; /* 43-44 */ int32_t magic2; /* 45-48 */ char pad2[8]; /* 49-56 */ int16_t magic3; /* 57-58 */ char pad3[6]; /* 59-64 */ int16_t magic4; /* 65-66 */ in_port_t boundport; /* 67-68 */ char pad4[104]; /* 69-172 */ char NTLMSSP[sizeof("NTLMSSP")]; /* 173-180: "NTLMSSP" */ int16_t magic5; /* 181-182: 0x03, 0x00 */ char pad5[2]; /* 183-184 */ int16_t magic10; /* 185-186: 0x18, 0x00 */ int16_t magic15; /* 187-188: 0x18, 0x00 */ int16_t magic20; /* 189-190: 0x49, 0x00 */ char pad10[6]; /* 191-196 */ int16_t magic30; /* 197-198: 0x61, 0x00 */ char pad15[2]; /* 199-200 */ int16_t magic35; /* 201-202: 0x08, 0x00 */ int16_t magic40; /* 203-204: 0x08, 0x00 */ int16_t magic45; /* 205-206: 0x34, 0x00 */ char pad20[2]; /* 207-208 */ int16_t magic50; /* 209-210: 0x07, 0x00 */ int16_t magic55; /* 211-212: 0x07, 0x00 */ int16_t magic60; /* 213-214: 0x3c, 0x00 */ char pad25[2]; /* 215-216 */ int16_t magic65; /* 217-218: 0x06, 0x00 */ int16_t magic70; /* 219-220: 0x06, 0x00 */ int16_t magic75; /* 221-222: 0x43, 0x00 */ } _4; struct { unsigned char hostlength; /* length of host, including NUL. */ char pad1[17]; /* 39-56 */ char *host; /* 57-... */ } resolve; struct { int16_t magic1; /* 39-40 */ char pad1[4]; /* 41-45 */ int32_t magic3; /* 45-48 */ char pad5[8]; /* 48-56 */ int16_t magic6; /* 57-58: 0x0200 */ in_port_t destport; /* 59-60 */ in_addr_t destaddr; /* 61-64 */ char pad10[4]; /* 65-68 */ int16_t magic10; /* 69-70 */ char pad15[2]; /* 71-72 */ in_port_t srcport; /* 73-74: port client connects from */ char pad20[82]; /* 75-156 */ } _5; struct { int16_t magic1; /* 39-40 */ char pad5[2]; /* 41-42 */ int16_t magic5; /* 43-44 */ int32_t magic10; /* 45-48 */ char pad10[2]; /* 49-50 */ int16_t magic15; /* 51-52 */ int32_t magic16; /* 53-56 */ int16_t magic20; /* 57-58 */ in_port_t clientport; /* 59-60: forwarded port. */ in_addr_t clientaddr; /* 61-64: forwarded address. */ int32_t magic30; /* 65-68 */ int32_t magic35; /* 69-72 */ in_port_t serverport; /* 73-74: port server will connect * to us from.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -