Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

C++ Recv in a while loop and compare recv

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");
 }
 } 
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?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by gigajewNov 26, 2018 05:51 AM 1 248 Nov 26, 2018 05:51 AM
Last Post: Nick (Name)
[C] by F.A.S.TJul 30, 2018 03:59 PM 8 253 Jul 30, 2018 03:59 PM
Last Post: F.A.S.T
[C] by GoliaXJul 16, 2018 08:26 PM 3 169 Jul 16, 2018 08:26 PM
Last Post: Auriana