fsteff
fsteff

Reputation: 553

Rebol 2 port binding to multiple IPs

I have a Windows setup with multiple IP's, and wishes my Rebol script (on Rebol/Core 2.78) to make individual bind and listen to the same port number on each of those IP's.

Until very recently I thought the syntax to do this was:

Port1Test: open/lines tcp://:80   browse http://10.100.44.6?
Port2Test: open/lines tcp://:80   browse http://10.100.44.7?

But it turns out the Port2Test line fails, as the browse http://10.100.44.6? part is totally ignored (and now searching, I can't even locate where I got that syntax in the first place).
Reading up on the documentation all I can find on how to specify a listening port is like this:

Port1Test: open/lines tcp://:80

Probing the Port1Test port reveals most settings set to none, and a few set as follows:

scheme: 'tcp
host: none
port-id: 80
local-ip: 0.0.0.0
local-port: 80

So I attempted to modify those values like this:

Port1Test: open/lines tcp://:80  ; Create port, as before. Then modify below
Port1Test/host: 10.100.44.6      ; Might this be the binding interface?
Port1Test/port-id: 1             ; I guess this is just an id?
Port1Test/local-ip: 10.100.44.6  ; This ought to be the binding interface.

Port2Test: open/lines tcp://:80  ; Create port, as before. Then modify below
Port2Test/host: 10.100.44.7      ; Might this be the binding interface?
Port2Test/port-id: 2             ; I guess this is just an id?
Port2Test/local-ip: 10.100.44.7  ; This ought to be the binding interface.

Unfortunately all variations of the above modifications, including swapping the IP values for Port1Test and Port2Test, fails when creating Port2Test. :-(

I'm sure there's something I'm overlooking, but I can't find any hints anywhere about how to initialize a port while binding it to a specific interface.

Any hints highly appreciated!


Edit: The way Rebol bind to interfaces is now pretty evident to me - but how to modify it it still a mystery.

Let’s say I have two IP’s (== interfaces) associated to one networking card: 10.100.1.1 and 10.100.1.2. On 10.100.1.1:80 I setup a Tomcat application that I know can bind to that specific interface. Then I start a REBOL application, that also claim port 80. They will both run happily, and each be accessible on only one IP, as if the Rebol application had bound to 10.100.1.2. Then I shut down the Tomcat application, and attempt to start it. This turns out not to be possible, as the interface is in use. And if I access both of the IP’s, it turns out the Rebol application is accessible on both IP’s.

It’s not an active mechanism in Rebol that at work here, but because Rebol claims the 0.0.0.0 interfaces (In the context of servers, 0.0.0.0 means "all IPv4 addresses on the local machine"), which is translated to any currently available interface, and a deferred claim to interfaces as they become available.

It would be really nice to find out how to change Rebols default interface of 0.0.0.0 to something else at create time of the port!

Upvotes: 4

Views: 129

Answers (1)

DocKimbel
DocKimbel

Reputation: 3199

Rebol2 listen ports bind by default to all available IPv4 interfaces (0.0.0.0), and to the extent of my knowledge, unfortunately, there is no way to change that.

FYI, Rebol2 exposes existing IPv4 interfaces using the interfaces port mode:

>> p: open tcp://:8000
>> probe get-modes p 'interfaces
[make object! [
        name: "if19"
        addr: 10.27.10.110
        netmask: 255.255.255.252
        broadcast: 10.27.10.111
        dest-addr: none
        flags: [broadcast multicast]
    ] make object! [
        name: "lo0"
        addr: 127.0.0.1
        netmask: 255.0.0.0
        broadcast: none
        dest-addr: none
        flags: [multicast loopback]
    ] make object! [
        name: "if16"
        addr: 192.168.1.4
        netmask: 255.255.255.0
        broadcast: 192.168.1.255
        dest-addr: none
        flags: [broadcast multicast]
    ]]

Alas, this is read-only...(the documentation says not settable).

You can find a list of all port modes here, in case it is of any help to you.

Upvotes: 1

Related Questions