plPgSQL + CDIR/INET types ...

Started by The Hermit Hackerabout 16 years ago3 messagesgeneral
Jump to latest
#1The Hermit Hacker
scrappy@hub.org

Has anyone either played with, or gotten to work, a plPgSQL function that
would take: 192.168.1.1/24 and determine the start and end IP from that?
Or even start IP + # of IPs in the subnet?

----
Marc G. Fournier Hub.Org Hosting Solutions S.A.
scrappy@hub.org http://www.hub.org

Yahoo:yscrappy Skype: hub.org ICQ:7615664 MSN:scrappy@hub.org

#2Steve Atkins
steve@blighty.com
In reply to: The Hermit Hacker (#1)
Re: plPgSQL + CDIR/INET types ...

On Mar 30, 2010, at 7:09 PM, Marc G. Fournier wrote:

Has anyone either played with, or gotten to work, a plPgSQL function that would take: 192.168.1.1/24 and determine the start and end IP from that? Or even start IP + # of IPs in the subnet?

If that was a valid cidr value (like 192.168.1.0/24) you could just use host() or broadcast() to get the first and last addresses (and subtraction to get the size of the subnet).

You could probably convert it to the equivalent cidr range with some combo of set_masklen() and masklen().

Cheers,
Steve

#3Harald Fuchs
hari.fuchs@gmail.com
In reply to: The Hermit Hacker (#1)
Re: plPgSQL + CDIR/INET types ...

In article <alpine.BSF.2.00.1003302306490.97069@hub.org>,
"Marc G. Fournier" <scrappy@hub.org> writes:

Has anyone either played with, or gotten to work, a plPgSQL function
that would take: 192.168.1.1/24 and determine the start and end IP
from that? Or even start IP + # of IPs in the subnet?

Just install ip4r from pgfoundry, and you'll never look back at the old
cidr/inet types.