Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 16:47

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ Clientless - Recv Packets/Help

Discussion on C++ Clientless - Recv Packets/Help within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
meak1's Avatar
 
elite*gold: 220
Join Date: Jun 2007
Posts: 3,768
Received Thanks: 1,126
Question C++ Clientless - Recv Packets/Help

Rly often it happends that 2 or more Recv packets get stored into one..
so i get 2 Packets in one.

I need to sync or is something wrong with the Code ?
Thanks for help(;

Code:
int _ConnectIt(void * unused)
{
	printf("Connecting to 222.111.x.x - ***!\n");
	long rc;
	SOCKADDR_IN addr;

	rc=startWinsock();
	memset(&addr,0,sizeof(SOCKADDR_IN)); 
	addr.sin_family=AF_INET;
	addr.sin_port=htons(30001); 
	addr.sin_addr.s_addr=inet_addr("222.111.x.x");

	if(rc!=0) {
		printf("Fehler: startWinsock, fehler code: %d\n",rc);
		return 1;
	}
	else {
		printf("Winsock gestartet!\n");
	}
	s=socket(AF_INET,SOCK_STREAM,0);
	if(s==INVALID_SOCKET){
		printf("Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n",WSAGetLastError());
		return 1;
	}
	else{
		printf("Socket erstellt!\n");
	}

	if(!connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR))){
		printf("Verbunden mit ...\n");

		while(true)
		{
			if(!_Get_Recv())
				break;	
if(buf[2] == 0x2A){
				printf("Server Response, to Generate AESKey/Sync etc\n");
}
}
}
Code:
#define DEFAULT_BUFLEN 1024
char* buffer= (char*) malloc(1024);
int iResult, data;
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
char* buf;

bool _Get_Recv()
{
	char recvbuf[DEFAULT_BUFLEN];
	int recvbuflen = DEFAULT_BUFLEN;

	while(true){
		iResult = recv(s, recvbuf, recvbuflen, 0);

		if ( iResult > 0 ){
			printf("Bytes received: %d\n", iResult);
                        buf=recvbuf;
			return true;
		}else if ( iResult == 0 ){
			printf("Connection closed\n");
			system("PAUSE");
		}else{
			printf("recv failed: %d\n", WSAGetLastError());
			system("PAUSE");
		}
	}
}
meak1 is offline  
Old 04/18/2014, 21:18   #2
 
elite*gold: 1391
Join Date: Apr 2014
Posts: 77
Received Thanks: 14
TCP is a stream based protocol. It's not frame based so you can't be sure wether your data arrives in one or splitted. You need to store the data in a buffer and implement a protocol which gives information about packet boundaries.

like:
Code:
while(recvdata()){
 // append data to buffer
...

    if (bufferContainsCompletePacket)
    {
        // pull out packet and handle
        ...
    }
}
Further help:
Actidnoide is offline  
Old 04/19/2014, 14:41   #3
 
meak1's Avatar
 
elite*gold: 220
Join Date: Jun 2007
Posts: 3,768
Received Thanks: 1,126
ok, so the Code is correct and i just need to do an Filter?

like ->

Code:
if(buf[0] > iResult){ //buf[0] <- is the Packet Size in the Game.
-> Split Packet
}
Correct? i thought i could sync or smth, that it not get stored into one buffer(; - but as u said its Stream based :b
meak1 is offline  
Old 04/19/2014, 15:01   #4
 
elite*gold: 1391
Join Date: Apr 2014
Posts: 77
Received Thanks: 14
iResult only represents the amount of data received in one recv() call.
More like:

Code:
// curDataSize -> length of data received from recv()
if (curDataSize >= buf[0]){
-> Split Packet
}
So the first byte indicates the packet length.

But remember that a signed char (buf[i]) only allows a range from -128 to 127.
Actidnoide is offline  
Old 04/19/2014, 17:49   #5
 
meak1's Avatar
 
elite*gold: 220
Join Date: Jun 2007
Posts: 3,768
Received Thanks: 1,126
i know, i would do an *(WORD*)&buf[0]; ;> Thanks anyway(;
trying it later ;E
meak1 is offline  
Reply


Similar Threads Similar Threads
Packets to recv when login?
04/18/2013 - DarkOrbit - 1 Replies
hi my question is which packets should the 2010 client recv after sending login packet? never sniffed darkorbit packets before half of 2012 so i never could decrypt packets and look what does it sends. i made a basic emu, very basic just for testing (send/recv) and my problem is when i recv login packet i dont know what should i send (supossing login sucess). tried with add hero ship packet "I", new map "m" or update position "D" so i came here to ask u guys thanks
[Release] +5500 Packets structure , client/packets constants
10/07/2012 - CO2 PServer Guides & Releases - 10 Replies
edit : if u know nothing about packets go to this post first explaining what is packets , and explaining a packet with details and everything http://www.elitepvpers.com/forum/co2-pserver-disc ussions-questions/2162344-packets-packets-packets. html#post19074533 i start making my very own packet structure to use them on my new proxy but i thought of ripping them from the source so yeah the following packets is ripped of trinity base source right now im just providing the packets structure...
[C++] Recv packets from webbrowser...
03/20/2012 - General Coding - 4 Replies
Hello guys! I have a question to you. I want make bot as: http://www.elitepvpers.com/forum/browsergames/176 3240-release-seafight-antistealth-wartool-bot.html and I don't know how recv packets which seafight server send to webbrowser? I must use winsock or winpcap? I try make serwer: #include <cstdio> #include <winsock2.h> #include <iostream>
[Question] Hooking send() & recv() works, but recv hiding data for co???
05/06/2009 - CO2 Programming - 2 Replies
Hey guys, I've been making a DLL to allow another program to intercept the packets of conquer using windows pipes. (Then its the job of the main program to decrypt the packets, the DLL only gives a communication channel for the main program) (winsock functions btw) - hooking send() works fine for my internet browser - hooking recv() works fine for my internet browser - hooking send() works fine for conquer online



All times are GMT +1. The time now is 16:51.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.