Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a game client. Which connects to this game. I'm trying to set up a socket server which intercepts all traffic to the game server(The game runs through the use of sockets)

My problem is that i would need to redirect all traffic my computer makes to the game servers ip + port to to make it connect to the socket server i've made myself first.

I know i could use the windows hosts file but this redirects ALL traffic. I only want 1 port redirected(The one with TCP traffic) If the HTTP traffic also gets redirected it ruins everything.

I'm using windows 7 The programming language is java.

share|improve this question

closed as off topic by Khaled, pfo, David Schwartz, Wesley, MDMarra May 9 '12 at 18:37

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Programming question -> stackoverflow. – Khaled Apr 17 '12 at 8:49

You can do this with a Layered Service Provider (LSP). What you need to do is intercept that operation that makes the connection and change the destination IP address (and possibly port). It's possible you might also need to intercept operations to get the remote socket address to make it consistent with what the application expected, but it's not likely. Applications don't usually check the remote address of TCP connections they initiated.

A simpler way is to hook the WSAConnect call the application makes and change the destination IP address directly. You could do this a number of ways. For example, you could use Microsoft Detours. You could also give the application your own Winsock DLL that forwards operations to the regular one. There are numerous other API intercept methods as well.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.