Home > Software engineering >  Install forwarding sock5 LSP
Install forwarding sock5 LSP

Time:10-01

LSP installation code written the DLL is written about the same now found a problem has been bothering me for a few days...

Is his own after the DLL installed to the LSP on firefox browser can completely through sock5 agent forward packets! But slowly open a web page to wait for a long time not slow agent is my code has a problem!

And after installation of LSP Google browser nowhere! I think maybe is my hook WSPConnect function when I changed the socket obstruction caused by!


I am full of the great god! Look!





//connection socks5 agent 
Int socksProxy (SOCKET s, const struct sockaddr * name, int namelen)
{
IP char []="115.47.40.65";
Int host=1085;
Char user []="user";
Char password []="sock5";



Int rc=0;
//here should first save the types of blocking/non-blocking sockets at the back according to the value return it here, but I don't know how to get this type
//modify the socket for blocking type

Unsigned long nonBlock=0;

Rc=WSAEventSelect (s, 0, NULL);
Rc=ioctlsocket (s, FIONBIO, & amp; NonBlock);//the real change for blocking type



//connection proxy server
Sockaddr_in serveraddr;
Memset (& amp; Serveraddr, 0, sizeof (serveraddr));
Serveraddr. Sin_family=AF_INET;
Serveraddr. Sin_addr. S_un. S_addr=inet_addr (IP);
Serveraddr. Sin_port=htons (host);//port
WSABUF DataBuf;
Char buffer [4].
Memset (buffer, 0, sizeof (buffer));
DataBuf. Len=4;
DataBuf. Buf=buffer;
Int err=0;
If ((rc=NextProcTable. LpWSPConnect (s, (struct sockaddr *) & amp; Serveraddr, sizeof (struct sockaddr), & amp; DataBuf, NULL, NULL, NULL, & amp; Err))!=0)
{
Return the rc;
}



//send the request to negotiate version and authentication methods
//VER NMETHODS the METHODS
//1 1 1 to 255
Char verstring [257].
Verstring [0]=0 x05;//VER (1 Byte)
Verstring [1]=0 x01;//NMETHODS (1 Byte)
Verstring [2]=0 x00;//the METHODS (1-255 bytes, allow current 1 byte)
If ((rc=send (s, verstring, 3, 0)) & lt; 0)
{
Return the rc;
}
//receive the proxy server to return information
//VER METHOD
//1 1
/* currently defined methods include:
X '0', don't need certification
, X '01' GSSAPI
X '02' username/password
7 · X '03 -' X 'f' assigned by IANA
, '80' X - X "FE" reserved for private method
, X 'FF' there is no acceptable way */

Char ver [2].
If (recv (s, ver, 2, 0) & lt; 0)
{
Return ECONNABORTED;
}
//proxy server selection method
//determine whether our method feasible
If (ver [1]==0 XFF)
{
Return ECONNREFUSED;
}
//methods 0: don't need certification 02 account password authentication
If (ver [1]==0 x00 | | ver [1]==0 x02)
{

//password authentication
If (ver [1]==0 x02)
{

Char Buffer [50].
* (int *) (Buffer + 0)=(int) 1;
Int the UI=strlen (user);
Memcpy (Buffer + 1, (char *) & amp; UI, 1);
Memcpy (Buffer + 2, user, UI);

Int PI=strlen (password);
Memcpy (Buffer + 2 + UI, (char *) & amp; PI, 1);
Memcpy (Buffer + 1 + 2 + UI, password, PI);

If ((rc=send (s, Buffer, 3 + UI + PI, 0)) & lt; 0)
{
Return the rc;
}


If ((rc=recv (s, Buffer, 2, 0)) & lt; 0)
{
Return ECONNREFUSED;
}

If (Buffer [1].=0 x00) {
Return ECONNREFUSED;
}

}


//send the SOCKS request
//VER CMD RSV ATYP DST. ADDR DST. PROT
//1 1 X '00' 1 Variable 2
/* VER protocol version: X '05'
CMD,
CONNECT: X '01'
The BIND: X '02'
The UDP ASSOCIATE: X '03'
RSV, keep
· ATYP behind the address type
IPV4: X '01'
Domain name: X '03'
IPV6: X '04' '
· DST. ADDR destination address
· DST. PORT PORT number, in the network byte order
The SOCKS server will analysis the request according to the source and destination addresses, and then return to one or more responses, depending on the type of request */


Struct sockaddr_in sin;
Sin=* (const struct sockaddr_in *) name;
Char buf [10].
Buf [0]=0 x05;//version SOCKS5
Buf [1]=0 x01;//connection request
Buf [2]=0 x00;//keep field
Buf [3]=0 x01;//IPV4
Memcpy (& amp; Buf [4], & amp; Sin. The sin_addr. S_un S_addr, 4);
Memcpy (& amp; Buf [8], & amp; Sin. Sin_port, 2);
//send

If ((rc=send (s, buf, 10, 0)) & lt; 0)
{
Return the rc;
}

//reply
//VER REP RSV ATYP BND. ADDR BND. PORT
//1 1 X '00' 1 Variable 2
/* VER protocol version: X '05'
REP response fields:
, X '0' success
, X '01' ordinary SOCKS server requests failed
X, '02' existing rules do not allow the connection of
, X '03' network inaccessible
X, '04' host unreachable
X '05,' connection refused
, X '06' TTL timeout
, X '07' does not support the command
, X '08' does not support the type of address
, '09' X - X 'FF' undefined
RSV, keep
· ATYP behind the address type
IPV4: X '01'
Domain name: X '03'
IPV6: X '04'
· BND. ADDR server binding address
· BND. PORT in network byte order said server binding period of mouth
Identified as RSV field must be set to '0', X */
If ((rc=recv (s, buf, 10, 0)) & lt; 0)
{
Return ECONNREFUSED;
}


If (buf [1].=0 x00)
{
The switch ((int) buf [1])
{
Case 1:
Return ECONNABORTED;
Case 2:
Return ECONNABORTED;
Case 3:
Return ENETUNREACH;
Case 4:
Return EHOSTUNREACH;
Case 5:
Return ECONNREFUSED;
Case 6:
Return ETIMEDOUT;
Case 7:
Return ECONNABORTED;
Case 8:
Return ECONNABORTED;
Default:
Return ECONNABORTED;
}
} else {

//modify the socket is non-blocking type
NonBlock=1;
If (rc=ioctlsocket (s, FIONBIO, & amp; NonBlock))
{
Return the rc;
}
return 0;

}
}

Return ECONNABORTED;
}








//WSPConnect
Int WSPAPI WSPConnect (
The SOCKET s,
Const struct sockaddr * name,
Int namelen,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related