Re: My the client point have a problem.But where don't I take place?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



My reply is at the bottom of your message:

"Z.Smith" <zhchyg@xxxxxxx> wrote
>
> client -----> proxy ---------------> server
> 1.1.51.227:8000 1.1.51.227:1080
> 1.1.51.227:8001
>
> SOCKET tcp,udp;
> sockaddr_in clientaddr,proxyaddr,proxyaddr1,remoteaddr;
> char m_sz_udp_srv[1024];
> u_short m_n_port;
> char buf[1024];
> CString str;
>
> udp = socket(AF_INET,SOCK_DGRAM,0);
> tcp = socket(AF_INET,SOCK_STREAM,0);
>
> clientaddr.sin_family = AF_INET;
> clientaddr.sin_addr.s_addr= inet_addr("1.1.51.227");
> clientaddr.sin_port = htons(8000);
>
> bind(udp,(sockaddr*)&clientaddr,sizeof(clientaddr));
>
> proxyaddr.sin_family = AF_INET;
> proxyaddr.sin_addr.s_addr= inet_addr("1.1.51.227");
> proxyaddr.sin_port = htons(1080);
>
> remoteaddr.sin_family = AF_INET;
> remoteaddr.sin_addr.s_addr= inet_addr("1.1.51.227");
> remoteaddr.sin_port = htons(8001);
>
> if(connect(tcp,(sockaddr*)&proxyaddr,sizeof(proxyaddr))==SOCKET_ERROR)
> {
> closesocket(tcp);
> return;
> }
>
> memset(buf,0,1024);
> buf[0]=0x05;
> buf[1]=0x02;
> buf[2]=0x00;
> buf[3]=0x02;
> send(tcp,buf,4,0);
>
> memset(buf,0,1024);
> if(recv(tcp,buf,1024,0)==SOCKET_ERROR)
> {
> closesocket(tcp);
> return;
> }
>
> if(buf[0]==0x05 && buf[1]==0x02)
> {
> AfxMessageBox("need username and password!"); file://My proxy server not
> need
> }
> else if(buf[0]!=0x05 || buf[1]!=0x00)
> {
> closesocket(tcp);
> return;
> }
>
> memset(buf,0,1024);
> buf[0]=0x05;
> buf[1]=0x03;
> buf[2]=0x00;
> buf[3]=0x01;
>
> *((int *)(&buf[4])) = clientaddr.sin_addr.s_addr;
> *((short *)(&(buf[8]))) = (short)clientaddr.sin_port;
>
> send(tcp,buf,10,0);
>
> memset(buf,0,1024);
> if(recv(tcp,buf,1024,0)==SOCKET_ERROR)
> {
> closesocket(tcp);
> return;
> }
> if(buf[0]!=0x05 || buf[1]!=0x00)
> {
> closesocket(tcp);
> return;
> }
>
> if(buf[3]==0x01)
> {
> file://can come to here
> int n_ip = *((int *)&buf[4]);
> in_addr in;
> in.S_un.S_addr = n_ip;
> memset((void *)m_sz_udp_srv,0,sizeof(m_sz_udp_srv));
> strcpy(m_sz_udp_srv,inet_ntoa(in));
> m_n_port = htons(*((unsigned short *)&(buf[8])));
> }
> else
> {
> closesocket(tcp);
> return;
> }
> file://sned a UDP data packet
> memset(buf,0,1024);
> buf[0] = 0x00;
> buf[1] = 0x00;
> buf[2] = 0x00;
> buf[3] = 0x01;
> buf[4]=(char)remoteaddr.sin_addr.S_un.S_un_b.s_b1;
> buf[5]=(char)remoteaddr.sin_addr.S_un.S_un_b.s_b2;
> buf[6]=(char)remoteaddr.sin_addr.S_un.S_un_b.s_b3;
> buf[7]=(char)remoteaddr.sin_addr.S_un.S_un_b.s_b4;
> *((SHORT*)(&(buf[8])))=remoteaddr.sin_port;
>
>
> buf[10] = 'A';
>
> proxyaddr1.sin_family = AF_INET;
> proxyaddr1.sin_addr.s_addr = inet_addr(m_sz_udp_srv);
> proxyaddr1.sin_port = htons(m_n_port);
>
> int addr_len;
> addr_len=sizeof(struct sockaddr);
> int returndatalen=sendto(udp,buf,1024,0,(struct sockaddr
> *)&proxyaddr1,addr_len);
> DWORD err = ::WSAGetLastError(); file://no error
>
> NetPacket pack;
> memset(&pack,0,sizeof(pack));
> returndatalen = recvfrom(udp,buf,1024,0,(struct sockaddr
> *)&proxyaddr1,&addr_len);
> err = ::WSAGetLastError(); file://no error
> if(err == 0)
> MessageBox(buf); file://display a dialog with empty char*
> else{
> str.Format("%d",err);
> MessageBox(str);
> }
> closesocket(tcp);
> closesocket(udp);

What's the problem ?
What error code do you get ?
Are you really ignoring the return value of bind(), send(), only checking
recv() for != SOCKET_ERROR ?


.



Relevant Pages

  • My the client point have a problem.But where dont I take place?
    ... char buf; ... CString str; ... int addr_len; ... int returndatalen=sendto(udp,buf,1024,0,(struct sockaddr ...
    (microsoft.public.win32.programmer.networks)
  • add route to routing table
    ... i am writing c code to add a route to the ... routing table and i'm creating a SOCK_RAW socket (int s = socket(PF_ROUTE, ... i am not sure about how to fill the sa_data field of sockaddr. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Linux 2.6.29.4
    ... static int is_efer_nx ... if (ret) ... struct ftdi_private { ... the specific security attributes of the socket ...
    (Linux-Kernel)
  • [PATCH] paccept, socket, socketpair w/flags
    ... there is a helper function to convert the new socket flags into ... socket() and socketpair. ... static int status; ... int fd1, fd2, err; ...
    (Linux-Kernel)
  • Re: reconnect tcp
    ... instance throws a fatal exception, ... to close the socket and reconnect. ... public ClientHandler(Socket client, int timeout) ... while (rxDataCounter < receiveBytes) ...
    (microsoft.public.dotnet.languages.csharp)