Hi, Is it possible to make a LaunchAgent listen on the first free port rather than a specific one? I'm trying to forward an HTTP connection on demand (over SSH), but rather than choose a specific local port I'd rather just choose a free one and then advertise it using Bonjour. So I also need to know what the chosen port was and pass it to dns-sd. A related question: is it possible (without writing to /etc/services) to make LaunchAgent listen on a port decided dynamically? i.e. would it be possible to use NAT-PMP to forward an external port to the first available local port, and then have a LaunchAgent listen on that port? Thanks, Hamish
On Nov 12, 2007, at 11:11 AM, Hamish Allan wrote:
Hi,
Is it possible to make a LaunchAgent listen on the first free port rather than a specific one?
Sure, set the port to zero. The kernel will dynamically assign a free port.
I'm trying to forward an HTTP connection on demand (over SSH), but rather than choose a specific local port I'd rather just choose a free one and then advertise it using Bonjour. So I also need to know what the chosen port was and pass it to dns-sd.
Actually, the launchd code should handle that for you. Just set Bonjour to true in the plist.
A related question: is it possible (without writing to /etc/services) to make LaunchAgent listen on a port decided dynamically? i.e. would it be possible to use NAT-PMP to forward an external port to the first available local port, and then have a LaunchAgent listen on that port?
I'm not sure what NAT-PMP is or how it applies to this scenario… davez
Hi Dave, On Nov 12, 2007 7:15 PM, Dave Zarzycki <zarzycki@apple.com> wrote:
Sure, set the port to zero. The kernel will dynamically assign a free port.
Ah, thanks.
Actually, the launchd code should handle that for you. Just set Bonjour to true in the plist.
Unfortunately, the SSH port is bound only to the loopback interface (so that others on my LAN cannot access it). As such, I need to register the service as being on localhost rather than mymachine.local, as per the following: $ dns-sd -P ServiceName _http._tcp . <port> localhost 127.0.0.1 However, the Bonjour key (which I set to "http" as the SockServiceName is 0) causes it to be registered as being on mymachine.local. Can I do anything about this? Thanks, Hamish
On Nov 12, 2007 10:51 PM, Hamish Allan <hamish@gmail.com> wrote:
I need to register the [Bonjour] service as being on localhost rather than mymachine.local [...] Can I do anything about this?
To answer my own question: from examining the source code, it would seem not. do_rendezvous_magic()'s call to DNSServiceRegister() is currently hardcoded to advertise on all interfaces. So to take another tack: is it possible to have launchd execute arbitrary commands after binding to a port, with the addrinfo available for substitution? Thanks, Hamish
On Nov 13, 2007, at 3:22 PM, Hamish Allan wrote:
On Nov 12, 2007 10:51 PM, Hamish Allan <hamish@gmail.com> wrote:
I need to register the [Bonjour] service as being on localhost rather than mymachine.local [...] Can I do anything about this?
To answer my own question: from examining the source code, it would seem not. do_rendezvous_magic()'s call to DNSServiceRegister() is currently hardcoded to advertise on all interfaces.
Please file a bug to fix that.
So to take another tack: is it possible to have launchd execute arbitrary commands after binding to a port, with the addrinfo available for substitution?
Nope. davez
participants (2)
-
Dave Zarzycki
-
Hamish Allan