Terminating Zero Problem

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2009
Posts: 32
Reputation: Schoorsteen is an unknown quantity at this point 
Solved Threads: 0
Schoorsteen Schoorsteen is offline Offline
Light Poster

Re: Terminating Zero Problem

 
0
  #41
Aug 12th, 2009
Oh, the server keeps sending 4,294,967,295 bytes, while the client sends 10 to 15. Is this right?

I doubt it.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Terminating Zero Problem

 
0
  #42
Aug 12th, 2009
There are different socket type protocols. Do you know what protocol the source and destination sockets are communicating with? Based upon the data you're seeing it doesn't look encrypted!

You're trying to intercept the message, by listening on any address.
Is your computer setup as a bridge? Two network cards? If not, how do you know the source isn't still communicating with the target!

Normally if you're trying to intercept, you aren't a node on a network, you put yourself in the data stream.
  1. NODE --------------------HOST --------------------------YOU
  2. NODE--/ \-----NODE
  3.  
  4.  
  5. NODE --------- > YOU < -------HOST
Which requires two separate sockets.
Otherwise you're just sniffing packets, not trying to relay them on the sly. Unless you have told the sender to send straight to you, and then you send them to where the sender originally wanted to go!




I'm not familiar with Python but what does its code look like!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Terminating Zero Problem

 
0
  #43
Aug 12th, 2009
4,294,967,295

0xffffffff (-1)

Check the error!

Sounds like you don't have your second connection between proxy and Host established!

let's see your code again!

  1. int rval = send( hSock, (const char *)vp, nLen, 0 );
  2. if (SOCKET_ERROR == rval)
  3. {
  4. closesocket( hSock );
  5. hSock = INVALID_SOCKET;
  6.  
  7. ELog( "Error: sendto() %s", ErrText( WSAGetLastError() ) );
  8. return false;
  9. }

  1.  
  2. //
  3. // Error String
  4. //
  5.  
  6. char *WSock::ErrText( int err )
  7. {
  8. static char buf[80];
  9.  
  10. switch (err)
  11. {
  12. case WSAEINTR: // 10004
  13. return "(10004) WSAEINTR - Interrupted function call.";
  14.  
  15. case WSAEACCES: // 10013
  16. return "(10013) WSAEACCES - Permission Denied.";
  17.  
  18. case WSAEFAULT: // 10014
  19. return "(10014) WSAEFAULT - Bad Address.";
  20.  
  21. case WSAEINVAL: // 10022
  22. return "(10022) WSAEINVAL - Invalid Argument.";
  23.  
  24. case WSAEMFILE: // 10024
  25. return "(10024) WSAEMFILE - Too many open files.";
  26.  
  27. case WSAEWOULDBLOCK: // 10035
  28. return "(10035) WSAEWOULDBLOCK - Resource temporarily unavailable.";
  29.  
  30. case WSAEINPROGRESS: // 10036
  31. return "(10036) WSAEINPROGRESS , Operation now in progress.";
  32.  
  33. case WSAEALREADY: // 10037
  34. return "(10037) WSAEALREADY - Operation already in progress.";
  35.  
  36. case WSAENOTSOCK: // 10038
  37. return "(10038) WSAENOTSOCK - Socket operation on nonsocket.";
  38.  
  39. case WSAEDESTADDRREQ: // 10039
  40. return "(10039) WSAEDESTADDRREQ - Destination address required.";
  41.  
  42. case WSAEMSGSIZE: // 10040
  43. return "(10040) WSAEMSGSIZE - Message too long.";
  44.  
  45. case WSAEPROTOTYPE: // 10041
  46. return "(10041) WSAEPROTOTYPE - Protocol wrong type for socket.";
  47.  
  48. case WSAENOPROTOOPT: // 10042
  49. return "(10042) WSAENOPROTOOPT - Bad protocol option.";
  50.  
  51. case WSAEPROTONOSUPPORT: // 10043
  52. return "(10043) WSAEPROTONOSUPPORT - Protocol not supported.";
  53.  
  54. case WSAESOCKTNOSUPPORT: // 10044
  55. return "(10044) WSAESOCKTNOSUPPORT - Socket type not supported.";
  56.  
  57. case WSAEOPNOTSUPP: // 10045
  58. return "(10045) WSAEOPNOTSUPP - Operation not supported.";
  59.  
  60. case WSAEPFNOSUPPORT: // 10046
  61. return "(10046) WSAEPFNOSUPPORT - Protobol family not supported.";
  62.  
  63. case WSAEAFNOSUPPORT: // 10047
  64. return "(10047) WSAEAFNOSUPPORT - Address family not supported by protocol family.";
  65.  
  66. case WSAEADDRINUSE: // 10048
  67. return "(10048) WSAEADDRINUSE - Address already in use.";
  68.  
  69. case WSAEADDRNOTAVAIL: // 10049
  70. return "(10049) WSAEADDRNOTAVAIL - Cannot assign requested address.";
  71.  
  72. case WSAENETDOWN: // 10050
  73. return "(10050) WSAENETDOWN - Network is down.";
  74.  
  75. case WSAENETUNREACH: // 10051
  76. return "(10051) WSAENETUNREACH - Network is unreachable.";
  77.  
  78. case WSAENETRESET: // 10052
  79. return "(10052) WSAENETRESET - Network dropped connection on reset.";
  80.  
  81. case WSAECONNABORTED: // 10053
  82. return "(10053) WSAECONNABORTED - Software caused connection abort.";
  83.  
  84. case WSAECONNRESET: // 10054
  85. return "(10054) WSAECONNRESET - Connection reset by peer.";
  86.  
  87. case WSAENOBUFS: // 10055
  88. return "(10055) WSAENOBUFS - No buffer space available.";
  89.  
  90. case WSAEISCONN: // 10056
  91. return "(10056) WSAEIRCONN - Socket is already connected.";
  92.  
  93. case WSAENOTCONN: // 10057
  94. return "(10057) WSAENOTCONN - Socket is not connected.";
  95.  
  96. case WSAESHUTDOWN: // 10058
  97. return "(10058) WSAESHUTDOWN - Cannot Twx/Rcv after socket shutdown.";
  98.  
  99. case WSAETIMEDOUT: // 10060
  100. return "(10060) WSAETIMEDOUT - Connection timed out.";
  101.  
  102. case WSAECONNREFUSED: // 10061
  103. return "(10061) WSAECONNREFUSED - Connection refused.";
  104.  
  105. case WSAEHOSTDOWN: // 10064
  106. return "(10064) WSAEHOSTDOWN - Host is down.";
  107.  
  108. case WSAEHOSTUNREACH: // 10065
  109. return "(10065) WSAEHOSTUNREACH - No route to host.";
  110.  
  111. case WSAEPROCLIM: // 10067
  112. return "(10067) WSAEPROCLIM - Too many processes.";
  113.  
  114. case WSASYSNOTREADY: // 10091
  115. return "(10091) WSASYSNOTREADY - Network subsystem is unavailable.";
  116.  
  117. case WSAVERNOTSUPPORTED: // 10092
  118. return "(10092) WSAVERNOTSUPPORTED - Winsock.dll version out of range.";
  119.  
  120. case WSANOTINITIALISED: // 10093
  121. return "(10093) WSANOTINITIALISED - Successful WSARtartup not yet performed.";
  122.  
  123. case WSAEDISCON: // 10101
  124. return "(10101) WSAEDISCON - Graceful shutdown in progress.";
  125.  
  126. #ifdef WSATYPE_NOT_FOUND
  127. case WSATYPE_NOT_FOUND: // 10109
  128. return "(10109) WSATYPE_NOT_FOUND - Class type not found.";
  129. #endif
  130.  
  131. case WSAHOST_NOT_FOUND: // 11001
  132. return "(11001) WSAHOST_NOT_FOUND - Host not found.";
  133.  
  134. case WSATRY_AGAIN: // 11002
  135. return "(11002) WSATRY_AGAIN - Nonauthoritative host not found.";
  136.  
  137. case WSANO_RECOVERY: // 11003
  138. return "(11003) WSANO_RECOVERY - This is a nonrecoverable error.";
  139.  
  140. case WSANO_DATA: // 11004
  141. return "(11004) WSANO_DATA - Valid name, no data record of requested type.";
  142.  
  143. default:
  144. sprintf( buf, "(%d)", err );
  145. return buf;
  146. break;
  147. }
  148. }
Last edited by wildgoose; Aug 12th, 2009 at 4:48 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 32
Reputation: Schoorsteen is an unknown quantity at this point 
Solved Threads: 0
Schoorsteen Schoorsteen is offline Offline
Light Poster

Re: Terminating Zero Problem

 
0
  #44
Aug 12th, 2009
I know I intercept all the messages, because I can set up in the config what the server IP is, which is 127.0.0.1:1339 in this case.

I also know you need two sockets, I got a program running two sockets, but for the previous problem I just made a simplified version of my program.

I am not either familiar with Python, my cousin made this one:

  1. from socket import *;import thread,time,pickle;caddr=("127.0.0.1", 1337);saddr=("94.75.229.241", 7777);tijdbalk = [];infobalk = []
  2.  
  3. cl = socket(AF_INET,SOCK_DGRAM)
  4. cl.bind(("",1337))
  5.  
  6. sv = socket(AF_INET,SOCK_DGRAM)
  7. sv.connect(("94.75.229.241", 7777))
  8.  
  9. def a():
  10. global caddr,saddr,infobalk,tijdbalk
  11. while 1:
  12. try:
  13. (data, caddr) = cl.recvfrom(999999)
  14. tijdbalk.append(time.time())
  15. infobalk.append(data)
  16. sv.sendto(data, (saddr))
  17. except:
  18. None
  19.  
  20. def b():
  21. global caddr,saddr
  22. while 1:
  23. try:
  24. (data, saddr) = sv.recvfrom(999999)
  25. cl.sendto(data, (caddr))
  26. except:
  27. None
  28.  
  29. thread.start_new_thread(a,())
  30. thread.start_new_thread(b,())
  31.  
  32. raw_input("Done?")
  33. cl.close()
  34. sv.close()
  35. file = raw_input("Profile name: ")
  36. data = pickle.dumps([tijdbalk,infobalk])
  37. c = open(file,"wb")
  38. c.write(data)
  39. c.close()

I am now trying to find out what the error message is, I will let you know in a few minutes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 32
Reputation: Schoorsteen is an unknown quantity at this point 
Solved Threads: 0
Schoorsteen Schoorsteen is offline Offline
Light Poster

Re: Terminating Zero Problem

 
0
  #45
Aug 12th, 2009
I am sure it works trough UDP, because so does the Python script.

This is my real code:

  1. #include <cstdio>
  2. #include <winsock2.h>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. struct incSockets
  9. {
  10. SOCKET* sv;
  11. SOCKET* cl;
  12. sockaddr_in* clSockAddr;
  13. sockaddr_in* svSockAddr;
  14. };
  15.  
  16. void filter( char* packet, int nPacketLen )
  17. {
  18. while (nPacketLen > 0)
  19. {
  20. cout << "(" << int(*packet) << ")";
  21. packet++;
  22. nPacketLen--;
  23. }
  24. cout << endl;
  25. }
  26.  
  27. DWORD WINAPI svtocl(void* param)
  28. {
  29. cout << "Arived in thread SVTOCL" << endl;
  30. struct incSockets* incs = static_cast<struct incSockets*>(param);
  31.  
  32. SOCKET cl = *incs->cl;
  33. SOCKET sv = *incs->sv;
  34. sockaddr_in clSockAddr = *incs->clSockAddr;
  35. sockaddr_in svSockAddr = *incs->svSockAddr;
  36.  
  37. char buffer[999999];
  38. size_t bytesReceived;
  39. int fromlen = 999999;
  40. int bytes_sent;
  41.  
  42. while(true){
  43.  
  44. bytesReceived = recvfrom(sv, buffer, 999999, 0, (struct sockaddr *)&svSockAddr, &fromlen);
  45.  
  46. if(bytesReceived < 0) {
  47. cout << "svtocl error" << endl;
  48. }
  49.  
  50. if(bytesReceived > 0)
  51. {
  52. cout << "Server: ";
  53. cout << "Bytes: " << bytesReceived << endl;
  54. Sleep(10000);
  55. }
  56.  
  57. bytes_sent = sendto(cl, buffer, 999999, 0, (struct sockaddr*)&clSockAddr, sizeof(struct sockaddr_in));
  58.  
  59. }
  60.  
  61. }
  62.  
  63. DWORD WINAPI cltosv(void* param)
  64. {
  65. cout << "Arived in thread CLTOSV" << endl;
  66. struct incSockets* incs = static_cast<struct incSockets*>(param);
  67.  
  68. SOCKET cl = *incs->cl;
  69. SOCKET sv = *incs->sv;
  70. sockaddr_in clSockAddr = *incs->clSockAddr;
  71. sockaddr_in svSockAddr = *incs->svSockAddr;
  72.  
  73. char buffer[999999];
  74. size_t bytesReceived;
  75. int fromlen = 999999;
  76. int bytes_sent;
  77.  
  78. while(true){
  79.  
  80. bytesReceived = recvfrom(cl, buffer, 999999, 0, (struct sockaddr *)&clSockAddr, &fromlen);
  81.  
  82. if(bytesReceived < 0) {
  83. cout << "cltosv error" << endl;
  84. }
  85.  
  86. if(bytesReceived > 0)
  87. {
  88. cout << "Client: ";
  89. cout << "Bytes: " << bytesReceived << endl;
  90. //filter(buffer, bytesReceived);
  91. }
  92.  
  93. bytes_sent = sendto(sv, buffer, 999999, 0, (struct sockaddr*)&svSockAddr, sizeof(struct sockaddr_in));
  94.  
  95. //Sleep(3000);
  96. }
  97.  
  98. }
  99.  
  100. int main(int argc, char** argv) {
  101.  
  102. struct incSockets incs;
  103.  
  104. const int iReqWinsockVer = 2;
  105.  
  106. WSADATA wsaData;
  107.  
  108. if (WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0)
  109. {
  110. if (LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
  111. {
  112. SOCKET cl = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  113. SOCKET sv = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  114.  
  115. if (cl==INVALID_SOCKET)
  116. {
  117. cout << "Client: 1" << endl;
  118. }
  119.  
  120. if(sv == INVALID_SOCKET)
  121. {
  122. cout << "Server: 1" << endl;
  123. }
  124.  
  125. sockaddr_in clSockAddr;
  126.  
  127. memset(&clSockAddr, 0, sizeof(clSockAddr));
  128.  
  129. clSockAddr.sin_family = AF_INET;
  130. clSockAddr.sin_port = htons(1339);
  131. clSockAddr.sin_addr.S_un.S_addr = INADDR_ANY;
  132.  
  133. if (bind(cl, (sockaddr*)(&clSockAddr), sizeof(clSockAddr))!=0)
  134. {
  135. cout << "Client: 2" << endl;
  136. }
  137.  
  138. sockaddr_in svSockAddr;
  139.  
  140. memset(&svSockAddr, 0, sizeof(svSockAddr));
  141.  
  142. svSockAddr.sin_family = AF_INET;
  143. svSockAddr.sin_port = htons(7777);
  144. svSockAddr.sin_addr.S_un.S_addr = inet_addr("94.75.229.241");
  145.  
  146. incs.clSockAddr = &clSockAddr;
  147. incs.svSockAddr = &svSockAddr;
  148. incs.cl = &cl;
  149. incs.sv = &sv;
  150.  
  151. void* pIncs = &incs;
  152.  
  153. DWORD threadId1;
  154. CreateThread(0, 0, cltosv, pIncs, 0, &threadId1);
  155.  
  156. DWORD threadId2;
  157. CreateThread(0, 0, svtocl, pIncs, 0, &threadId2);
  158.  
  159. while(true) {}
  160.  
  161. closesocket(cl);
  162. closesocket(sv);
  163. }
  164. else
  165. {
  166. // Required version not available
  167. }
  168.  
  169. // Cleanup winsock
  170. if (WSACleanup()!=0)
  171. {
  172. // cleanup failed
  173. }
  174. }
  175. else
  176. {
  177. // startup failed
  178. }
  179. return 0;
  180. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Terminating Zero Problem

 
0
  #46
Aug 12th, 2009
Okay the Python code uses two threads. One deals with catching and relaying. The other the returned data.

The question now comes, which has been tickling at me, why are you trying to intercept client-host traffic?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 32
Reputation: Schoorsteen is an unknown quantity at this point 
Solved Threads: 0
Schoorsteen Schoorsteen is offline Offline
Light Poster

Re: Terminating Zero Problem

 
0
  #47
Aug 12th, 2009
(10022) WSAEINVAL - Invalid Argument.
Is the error I get.

Oh, why I do this.

Well, it is for Grand Theft Auto San Andreas Multi-Player. GTA SAMP.

If I know the packets I receive I can alter them. I am planning to make some kind of bot, but most of all, just because it's possible, and I thought this was a nice way to learn programming better.
Last edited by Schoorsteen; Aug 12th, 2009 at 5:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Terminating Zero Problem

 
0
  #48
Aug 12th, 2009
You do not send (-) or 0 bytes! You need to only relay if bytes received is (> 0).

As to an error, you need to handle different errors appropriately.
Last edited by wildgoose; Aug 12th, 2009 at 5:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Terminating Zero Problem

 
1
  #49
Aug 12th, 2009
good luck however if the server was written properly, the client is merely a playback. It can only request things of the server and its the servers job to validate a message, detect an invalid message, then log it and notify a service rep about a possible violation of rules!
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 32
Reputation: Schoorsteen is an unknown quantity at this point 
Solved Threads: 0
Schoorsteen Schoorsteen is offline Offline
Light Poster

Re: Terminating Zero Problem

 
0
  #50
Aug 12th, 2009
The thing is, I guess when I fixed the (10022) WSAEINVAL - Invalid Argument we might've fixed it.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC