Thread: Sockets and firewalls

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    4

    Sockets and firewalls

    I am programming an app that needs to work sort of like a p2p app, or aim. If someone has a router, but they have clients on the inside of their network that need to receive a file, how would you send that file to them, without a port on the router being forwarded? Also, how would you, when you send to their IP, distinguish between hosts on the internal network. Like, if the you send the file to 66.145.2.1, how would it know to go to 192.168.1.25, rather than 192.168.1.19?

    How would I go about coding something like this?

  2. #2
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    Like, if the you send the file to 66.145.2.1, how would it know to go to 192.168.1.25, rather than 192.168.1.19
    Basically, information sent will also have the recipients MAC address layered in the packet. When a packet is broadcast over a network, all machines on the network will see the packet but only the NIC with the proper MAC address will accept it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well your router needs to implement this I imagine http://www.webopedia.com/TERM/N/NAT.html

    192.168.1.25 sends a message "gimme the file" to some IP address
    The router sees this, creates a NAT entry, and sends the message on as if it came from 66.145.2.1
    The server responds with the data back to 66.145.2.1
    The router sees the source of the message, looks up the appropriate NAT entry, and forwards it to 192.168.1.25

    Of course, overlaying this simple transaction may be a whole bunch of firewall rules which specify which ports / addresses are to be allowed.

    As far as your app is concerned, you just connect to the server IP address and let the NAT do it's stuff (firewall rules permitting).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    how would you send that file to them, without a port on the router being forwarded?
    If they dont forward a port, then the only way you can send them a file is if they connect to you.

Popular pages Recent additions subscribe to a feed