c++ - Would like to evaluate a comparison between two sockaddr_in structs -


presently in midst of constructing peer-to-peer network architecture , @ stage of creating recieve function accept messages multiple clients on network. when recvfrom function called - address of recent client have sent message main client loaded sockaddr_in struct called fromaddr. program designed loop through vector containing multiple instances of client class (each of hold neccessary information , functionality represent client on network), , find client instance sockaddr_in struct matches of recieved message. in program evaulation looks so:

void udpclass::checkid(message* mess, sockaddr_in fraeaddress) { sockaddr_in anaddr; //iterate through vector of clients , find 1 sent message for(int = 0; i<theclients.size(); i++) {     anaddr = theclients[i].getaddress();     //if address of recieved message matches address of current client     if((anaddr.sin_addr == fraeaddress.sin_addr) && (anaddr.sin_port == fraeaddress.sin_port))     {         //update local instance of client location data matches of recieved message         theclients[i].setx(mess->x);         theclients[i].sety(mess->y);     } } } 

when program compiled following error reported:

error 3 error c2678: binary '==' : no operator found takes left-hand operand of type 'in_addr' (or there no acceptable conversion)

as might inferred have tried evaluating expression comparing 2 sockaddr_in structs themselves:

if(anaddr == fraeaddress) 

which reports same error. question is: short of creating sockaddr_in class overloaded operator functions allow evaluate expression, simplest way of implementing comparison?

you may want test unsigned long members of in_addr this:

if((anaddr.sin_addr.s_addr == fraeaddress.sin_addr.s_addr) && (anaddr.sin_port == fraeaddress.sin_port)) 

or windows:

if((anaddr.sin_addr.s_addr == fraeaddress.sin_addr.s_addr) && (anaddr.sin_port == fraeaddress.sin_port)) 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

node.js - How to mock a third-party api calls in the backend -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -