Jump to content
  • Advertisement
Sign in to follow this  
Valmian

Comparing sockaddr_in

This topic is 5409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a multiplayer game. In the game, all the clients connect to a server. When a client receives data, to ensure there is no hacking, I want to compare the sockaddr_in I get from recvfrom() to the sockaddr_in of the server. How can I do that? Ilya

Share this post


Link to post
Share on other sites
Advertisement
i wonder, would this work?

bool CompareIP(sockaddr_in ptAddr1, sockaddr_in ptAddr2){
if(ptAddr1.sin_addr.S_un.S_addr==ptAddr2.sin_addr.S_un.S_addr)
return true;
return false;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by crupp
actually, IP addresses can be faked. that's called "spoofing".

Yes. But only with raw sockets. And its non-trivial. And if you spoof your IP address, you can't get a reply to any data you send. So don't worry about it.

Share this post


Link to post
Share on other sites
Additionally, many internet service providers won't actually accept spoofed packets -- the end-node routers (that you are talking to) will drop them.

If you want to be a little more secure about finding out who is actually talking to you, I wrote up a paper on Authentication for Games.

Share this post


Link to post
Share on other sites
The address you get from recvfrom will be the client one, not the server.

And you'll have to compare it anyway with a connected clients table to know who they are.

I am of course assuming that you are using UDP.

If you are using TCP you don't need to care about who someone is - it is normally safe to assume that if they are on the same socket, they are the same person - TCP hijacking is extremely difficult.

Essentially you'll only need to validate their identity when they open the socket if you're on TCP.

Mark

Share this post


Link to post
Share on other sites
ah.. but I am writing code for client (server is done by someone else) and I only need to see if I am getting data from the server or not. Players will not talk to each other directly. The game is for school so I am not too woried about security ;)
Thank you,
Ilya

Share this post


Link to post
Share on other sites
Quote:
Original post by markr
The address you get from recvfrom will be the client one, not the server.

And you'll have to compare it anyway with a connected clients table to know who they are.

I am of course assuming that you are using UDP.

If you are using TCP you don't need to care about who someone is - it is normally safe to assume that if they are on the same socket, they are the same person - TCP hijacking is extremely difficult.

Essentially you'll only need to validate their identity when they open the socket if you're on TCP.

Mark


Yeah, I am using UDP.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!