blah.... blah.... blah...

My blah....blah....blah....
My Photo
Location: Delhi, Delhi, India

I'm a hacker, a free software advocate, and a student.

25 February 2006


IPC using TCP/IP under Windows XP Firewall

After the release of Microsoft Windows XP Service Pack 2, there is a builtin firewall. Any software, that attempts to listen on any TCP/IP port is caught by this firewall. And, for small applications which uses TCP/IP on the same computer for IPC (Interprocess Communication) also get caught by the firewall. To ensure that they won't get stopped by firewall, change server to always listen on only local loopback address. Whereas usually, any server written will listen on all interfaces. Since, it is not required in this kind of application, for the purpose of security you should avoid this. There is a java sample code, I've written to illustrate this, although you can write any equivalent code in C/C++ or any language which has an interface with BSD Sockets, or Winsock.



public class FirewalledServer {
 private static int PORT = 19450;

 private static void Main() throws IOException {
  // instead of starting using traditional way:
  // ServerSocket server = new ServerSocket(PORT);
  ServerSocket server = new ServerSocket();

  // Get localhost:PORT address
  SocketAddress sockaddr = new InetSocketAddress(
       InetAddress.getLocalHost(), PORT);

  // Bind and listen to it with backlog 3 (you can have any backlog)
  server.bind(sockaddr, 3);
  Socket client = server.accept();
  System.out.printf("Connection arrived from %s\n", client.getRemoteSocketAddress());

 public static void main(String[] args0) {
  try {
  } catch(IOException e) {
   System.err.printf("I/O Error: %s\n", e.getMessage());

// vim:ts=4

I've tested above code in JDK 5.0 update 4 and it may work on earlier releases too. For accurate information check for the availability of routines. I was using Jext and whenever I started Jext, firewall blocks. So with the help of my friend's Unix Networking Programming by W. Richards Stevens, I got this idea.

Anyways, its a good practise to perform only what is required accurately or precisely

It will work on earlier releases of J2SE, but in that case you might have to change printf statements to their equivalent println representation.
Post a Comment

<< Home


200601   200602   200603   200604   200605  

This page is powered by Blogger. Isn't yours?

There are some of my webpages tooo...

This blog is [ INVALID XHTML v1.0 ] [ INVALID CSS v2.0 ]