Modify

Opened 12 years ago

Closed 12 years ago

#499 closed defect (invalid)

ipcalc poorly designed...

Reported by: TheCompWiz Owned by: developers
Priority: high Milestone: 0.9/rc6
Component: other Version:
Keywords: ipcalc Cc:

Description

Ipcalc in it's current state (in RC5) is not really designed for any subnet other than a 255.255.255.0 I only reciently discovered it's flaws when using dnsmasq with a 255.255.255.248 subnet. I've re-written it, and would like to propose the following:

#!/bin/sh

awk -f /usr/lib/common.awk -f - $* <<EOF
BEGIN {
        ipaddr=ip2int(ARGV[1])
        netmask=ip2int(ARGV[2])
        network=and(ipaddr,netmask)
        broadcast=or(network,compl(netmask))

        start=and(network,ip2int("255.255.255.0"))+ARGV[3]
        limit=network+1
        if (start<limit) start=limit
        limit=broadcast-1
        if (start>limit) start=network+1
        end=start+ARGV[4]
        if (end>limit) end=limit

        print "IP="int2ip(ipaddr)
        print "NETMASK="int2ip(netmask)
        print "BROADCAST="int2ip(broadcast)
        print "NETWORK="int2ip(network)
        print "PREFIX="32-bitcount(compl(netmask))

        # range calculations:
        # ipcalc <ip> <netmask> <start> <num>

        if (ARGC > 3) {
                print "START="int2ip(start)
                print "END="int2ip(end)
        }
}
EOF

I do know that this does not support the "dhcp_start" being an IP rather than a number, but that could be checked for using the network as a bit mask or checking if the value is between the "network" and "broadcast". This does work dnsmasq in it's current configuration, it would also support larger subnets than previously. (not sure if anyone would want to) (i.e. 10.0.0.0/255.255.254.0 etc...) as well as smaller subnets.

Attachments (0)

Change History (1)

comment:1 Changed 12 years ago by mbm

  • Resolution set to invalid
  • Status changed from new to closed

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.