Hack Forums
[C] C++ Recv in a while loop and compare recv - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] C++ Recv in a while loop and compare recv (/showthread.php?tid=5902640)



C++ Recv in a while loop and compare recv - F.A.S.T - Nov 2, 2018

Yeah, It's a Rat Protocol. I need to know how can I recv data, Compare it and follow out the tasks.
I was able to this  but something tells me this isn't an efficient way. :s

PHP Code

<?php 
while (true) {
 
iResult = recv(sockt, server_reply, sizeof(server_reply), NULL);
 if (
iResult == SOCKET_ERROR) {
 
std::cout << "ERROR " << WSAGetLastError() << std::endl;
 exit(
1);
 }

 
// The Managment Protocol : 
 
if (strcmp(server_reply, "help")) {
 
send_msg(sockt, "YES!");
 } else if(
strcmp(server_reply, "sysinfo"){
 
                        // sysinfo ( ͡° ͜ʖ ͡°)
 
               }
 else {
 
send_msg(sockt, "No man");
 }
 } 



RE: C++ Recv in a while loop and compare recv - Auriana - Nov 2, 2018

Comparing strings is slow, cases can differ, lead to buffer overflow issue, or incorrect data passed into compare functions.

With that said,
strcmp returns 0 on success. You should be checking,
Code
if(!strcmp(server_reply,"help")){//they require help}

Also you're only checking recv on a single socket. What are you going to do if you have two sockets? Three? 1000?