how calculate the number of ip addresses in a range?
saeedeh motlagh
saeedeh.motlagh at gmail.com
Sun Aug 11 04:40:05 UTC 2013
thank you all guys for your answers.
Peter, of course it's not my homework!!!!!! in fact, i have a program which
manages dhcp. i want to limit the number of ip address which can be
assigned by dhcp server. in order to do that, i should know how many ip
addresses are available in the range that is defined for server and if the
number of available ip addresses are greater than valid threshold, it's
error. so as you said, i should know the math for calculate this number.
thank you again guys for your answers but they do not solve my problem. any
body knows what is the formula to calculate the valid ip addresses for any
desired ranges?
Thanks
On Sat, Aug 10, 2013 at 5:19 AM, Damien Fleuriot <ml at my.gd> wrote:
>
>
> On 10 Aug 2013, at 01:07, Kimmo Paasiala <kpaasial at gmail.com> wrote:
>
> > On Sat, Aug 10, 2013 at 1:44 AM, Peter Wemm <peter at wemm.org> wrote:
> >> On Fri, Aug 9, 2013 at 9:34 AM, Fleuriot Damien <ml at my.gd> wrote:
> >>>
> >>> On Aug 8, 2013, at 10:27 AM, Peter Wemm <peter at wemm.org> wrote:
> >>>
> >>>> On Thu, Aug 8, 2013 at 12:04 AM, s m <sam.gh1986 at gmail.com> wrote:
> >>>>> hello guys,
> >>>>>
> >>>>> i have a question about ip addresses. i know my question is not
> related to
> >>>>> freebsd but i googled a lot and found nothing useful and don't know
> where i
> >>>>> should ask my question.
> >>>>>
> >>>>> i want to know how can i calculate the number of ip addresses in a
> range?
> >>>>> for example if i have 192.0.0.1 192.100.255.254 with mask 8, how
> many ip
> >>>>> addresses are available in this range? is there any formula to
> calculate
> >>>>> the number of ip addresses for any range?
> >>>>>
> >>>>> i'm confusing about it. please help me to clear my mind.
> >>>>> thanks in advance,
> >>>>
> >>>> My immediate reaction is.. is this a homework / classwork /
> assignment?
> >>>>
> >>>> Anyway, you can think of it by converting your start and end addresses
> >>>> to an integer. Over simplified:
> >>>>
> >>>> $ cat homework.c
> >>>> main()
> >>>> {
> >>>> int start = (192 << 24) | (0 << 16) | (0 << 8) | 1;
> >>>> int end = (192 << 24) | (100 << 16) | (255 << 8) | 254;
> >>>> printf("start %d end %d range %d\n", start, end, (end - start) + 1);
> >>>> }
> >>>> $ ./homework
> >>>> start -1073741823 end -1067122690 range 6619134
> >>>>
> >>>> The +1 is correcting for base zero. 192.0.0.1 - 192.0.0.2 is two
> >>>> usable addresses.
> >>>>
> >>>> I'm not sure what you want to do with the mask of 8.
> >>>>
> >>>> You can also do it with ntohl(inet_addr("address")) as well and a
> >>>> multitude of other ways.
> >>>
> >>>
> >>> Hold on a second, why would you correct the base zero ?
> >>> It can be a valid IP address.
> >>
> >> There is one usable address in a range of 10.0.0.1 - 10.0.0.1.
> >> Converting to an integer and subtracting would be zero. Hence +1.
> >>
> >> --
> >
> > To elaborate on this, for every subnet regardless of the address/mask
> > combination there are two unusable addresses: The first address aka
> > the "network address" and the last address aka the "broadcast
> > address". There may be usable address in between the two that end in
> > one of more zeros but those addresses are still valid. Some operating
> > systems got this horribly wrong and marked any address ending with a
> > single zero as invalid, windows 2000 was one of them.
> >
> > -Kimmo
>
>
> Kimmo,
>
> That is untrue regarding /31 netmasks where you theoretically have 2^1 -2
> addresses.
>
> With such a short netmask the only 2 addresses are usable.
> _______________________________________________
> freebsd-net at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscribe at freebsd.org"
>
--
*Sa.M*
More information about the freebsd-net
mailing list