Main Page | Alphabetical List | Class List | File List | Class Members | File Members

Socks4Socket.h

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 #ifndef _SOCKS4SOCKET_H
00024 #define _SOCKS4SOCKET_H
00025 
00026 #include <TcpSocket.h>
00027 #include <ISocketHandler.h>
00028 
00029 #define MAXLEN_USERID 1000
00030 
00031 class RemoteSocket;
00032 
00033 class Socks4Socket : public TcpSocket
00034 {
00035         enum state_t {
00036                 STATE_VN = 0,
00037                 STATE_CD,
00038                 STATE_DSTPORT,
00039                 STATE_DSTIP,
00040                 STATE_USERID,
00041                 STATE_TRY_CONNECT,
00042                 STATE_CONNECTED,
00043                 STATE_FAILED,
00044                 STATE_ACCEPT,
00045         };
00046         enum state5_t {
00047                 STATE5_VER = 0,
00048                 STATE5_NMETHODS,
00049                 STATE5_METHODS,
00050                 STATE5_FAILED,
00051                 STATE5_GSSAPI, // not implemented
00052                 STATE5_USERPASSWORD_VER,
00053                 STATE5_USERPASSWORD_ULEN,
00054                 STATE5_USERPASSWORD_UNAME,
00055                 STATE5_USERPASSWORD_PLEN,
00056                 STATE5_USERPASSWORD_PASSWD,
00057                 STATE5_VER2,
00058                 STATE5_CMD,
00059                 STATE5_RSV,
00060                 STATE5_ATYP,
00061                 STATE5_ALEN,
00062                 STATE5_DST_ADDR,
00063                 STATE5_DST_PORT,
00064         };
00065 public:
00066         Socks4Socket(ISocketHandler& );
00067         ~Socks4Socket();
00068 
00069         void OnAccept() {
00070                 printf("Incoming\n");
00071         }
00072         void OnRead();
00073         void Socks4Read();
00074         void Socks5Read();
00075 
00076         void Connected();
00077         void ConnectFailed();
00078         void Accept();
00079 
00080         void SetRemote(RemoteSocket *p) { m_pRemote = p; }
00081 
00082 private:
00083         Socks4Socket(const Socks4Socket& s) : TcpSocket(s) {} // copy constructor
00084         Socks4Socket& operator=(const Socks4Socket& ) { return *this; } // assignment operator
00085         void SetupConnect();
00086         void SetupBind();
00087         void DoSocks5();
00088 
00089         state_t m_state;
00090         char m_vn;
00091         char m_cd;
00092         unsigned short m_dstport;
00093         unsigned long m_dstip;
00094         char m_userid[MAXLEN_USERID];
00095         int m_userid_ptr;
00096         RemoteSocket *m_pRemote;
00097         // socks5 support
00098         bool m_bSocks5;
00099         state5_t m_state5;
00100         char m_s5_ver;
00101         unsigned char m_s5_nmethods;
00102         int m_s5_method;
00103         unsigned char m_s5_methods[256];
00104         // username/password method
00105         char m_s5_userpassword_ver;
00106         unsigned char m_s5_userpassword_ulen;
00107         int m_s5_uptr;
00108         char m_s5_userpassword_uname[256];
00109         unsigned char m_s5_userpassword_plen;
00110         int m_s5_pptr;
00111         char m_s5_userpassword_passwd[256];
00112         // socks5 cont'd
00113         char m_s5_ver2;
00114         char m_s5_cmd;
00115 //      char m_s5_rsv;//0
00116         char m_s5_atyp;
00117         unsigned char m_s5_alen;
00118         int m_s5_aptr;
00119         unsigned char m_s5_dst_addr[256];
00120         unsigned short m_s5_dst_port;
00121 };
00122 
00123 
00124 
00125 
00126 #endif // _SOCKS4SOCKET_H

Generated on Tue Oct 3 23:44:54 2006 for Socks4 Server by  doxygen 1.4.4