How to convert Network to IP?
For example 192.168.1.1/24 to 192.168.1.1
I want to read ip from dhcp-client and use it for ip route rule src-address
How to convert Network to IP?
For example 192.168.1.1/24 to 192.168.1.1
I want to read ip from dhcp-client and use it for ip route rule src-address
I just wrote that. Let me dig it up
If you’re defining routes manually I think you’ll find you may need the network address with mask as well, so this code produces both
{
:local tmpip 192.168.1.1/24
:local tmpmask ([:pick $tmpip ([:find $tmpip "/"] + 1) [:len $tmpip]])
:local tmpmaskInvert [:tonum (32 - $tmpmask)]
:local dhcpAddress [:toip [:pick $tmpip 0 [:find $tmpip "/"]]]
:local dhcpNetwork (([:toip ($dhcpAddress >> $tmpmaskInvert)] << $tmpmaskInvert) . "/" . $tmpmask)
:put ("$dhcpAddress, $[:typeof $dhcpAddress]")
:put ("$dhcpNetwork, $[:typeof $dhcpNetwork]")
}