• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NAT-PMP Broadcast Address?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NAT-PMP Broadcast Address?


  • Subject: Re: NAT-PMP Broadcast Address?
  • From: email@hidden
  • Date: Wed, 12 Sep 2007 13:00:41 -0600

On Sep 10, 2007, at 12:35 PM, Matt Slot wrote:

On Sep 10, 2007, at 1:56 PM, email@hidden wrote:
I am just wondering if I am missing something, like maybe I have to send a special discovery packet to get the address of the router, and then pass that to NAT-PMP so it can query the router address directly. Or, do I look in the system somewhere for the router address as seen in system prefs?

Here's the code I use to discover the address of my upstream router using BSD.


...

For OpenTransport, OTInetGetInterfaceInfo() will do the trick.

I actually ended up going the OTInetGetInterfaceInfo() route, because using a raw socket seems to require running as root:


InetInterfaceInfo	info;
InetHost		host;

if( OTInetGetInterfaceInfo( &info, kDefaultInetInterface ) != noErr ) ErrorDialog( "Can't get route" );
host = ntohl( info.fDefaultGatewayAddr );


I'm pretty sure that the port returned by OTInetGetInterfaceInfo() is in network byte order, which is why I converted to host byte order here. I also tested with route from the console:

route get 128.0.0.1 | grep -o 'gateway: .*' | awk '{ print $2 }'

For my code, this is easier to access from Carbon since I have code to exec shell commands, but I will just use OpenTransport() since it's more likely to work in the future.

On Sep 11, 2007, at 12:02 PM, Josh Graessley wrote:

Ya I will listen for changes, maybe with just the notifications that happen in the spec though. Also, I think I found a flaw in NAT-PMP...because you can't query what ports your machine opened? I want to be able to check a port and see what it is. But the only way to do that is to basically try to remove the port. You will get an error code if another machine is using the port. However, if your computer had a port allocated, you just get an answer that you successfully either got the port, or changed its timeout, which for removal is a timeout of 0. There doesn't seem to be a way to determine if the port was already open. I realize that is how the spec is designed to work, so that multiple requests return multiple success replies, but this still seems to be a pretty major thing to overlook.

This is by design. Do your own book keeping :) If you need a mapping, create it. Renew it periodically as a DHCP lease would be renewed (about half way through). When you're done with it, dispose of it.

I actually agree with this, because normally there is no need to spy on your neighbors, so it makes sense for each machine to do its own thing. However, I want to be able to bring up some kind of dialog like "Sorry, port 1234 is in use by 192.168.0.2" or whatever, so people can tell their buddies to stop hogging the port. I will just say the port is in use by another machine.


NAT-PMP does have a problem though, because it doesn't take into account that many processes share a machine. So the best I can really do is, try to get a port, and I might get into contention with another process, which will try to update it when half the lifetime is up. This is why there should have been a query command, to at least see if a port is in use by the machine. I guess that what will most likely happen is, both processes will get the port, with say external port 10000 mapped to internal port 5000 for process A, and port 20000 mapped to internal port 5000 for process B. If they both request the same port, they will get it, just with different lifetimes most likely, so no harm done. However, if my app tears down a mapping, it could close any TCP connections the other process is using on the port. I don't think there is any way to resolve this problem.

--Zack
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NAT-PMP Broadcast Address?
      • From: Josh Graessley <email@hidden>
    • Re: NAT-PMP Broadcast Address?
      • From: james woodyatt <email@hidden>
References: 
 >NAT-PMP Broadcast Address? (From: email@hidden)
 >Re: NAT-PMP Broadcast Address? (From: Matt Slot <email@hidden>)

  • Prev by Date: Re: Socket timeout issue
  • Next by Date: Re: NAT-PMP Broadcast Address?
  • Previous by thread: Re: NAT-PMP Broadcast Address?
  • Next by thread: Re: NAT-PMP Broadcast Address?
  • Index(es):
    • Date
    • Thread