Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Aug 2013 02:52:55 +0200
From:      Damien Fleuriot <ml@my.gd>
To:        Peter Wemm <peter@wemm.org>
Cc:        Kimmo Paasiala <kpaasial@gmail.com>, s m <sam.gh1986@gmail.com>, FreeBSD Net <freebsd-net@freebsd.org>
Subject:   Re: how calculate the number of ip addresses in a range?
Message-ID:  <CE96AB08-2FB1-4892-A60B-AFF98121FF0B@my.gd>
In-Reply-To: <CAGE5yCrZx%2Bey57XMcOjFt6iWrrRGJtbA1PH-1fHC1aU7MT_qXg@mail.gmail.com>
References:  <CAA_1SgEEeyCOk%2Bi9Zp725RfQ9s0tpELXL0SSBeiN%2B60z%2BxqYUg@mail.gmail.com> <CAGE5yCoBYS2%2BsHoQXZvWMNPTQeEEtDX7LAKSBHJAZ4_rA2-byQ@mail.gmail.com> <8B53C542-5CC3-45E6-AA62-B9F52A735EE5@my.gd> <CAGE5yCqURzYF2TYez6S6y=x4rWtKdL%2B-3zjGsDuz2LqGb18-RQ@mail.gmail.com> <CA%2B7WWSf_i7b66xSFP3Gk20Cq7v0mX_ynQg61GM9u1_0vZF5-wQ@mail.gmail.com> <CAGE5yCrZx%2Bey57XMcOjFt6iWrrRGJtbA1PH-1fHC1aU7MT_qXg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On 10 Aug 2013, at 01:17, Peter Wemm <peter@wemm.org> wrote:

> On Fri, Aug 9, 2013 at 4:07 PM, Kimmo Paasiala <kpaasial@gmail.com> wrote:=

>> On Sat, Aug 10, 2013 at 1:44 AM, Peter Wemm <peter@wemm.org> wrote:
>>> On Fri, Aug 9, 2013 at 9:34 AM, Fleuriot Damien <ml@my.gd> wrote:
>>>>=20
>>>> On Aug 8, 2013, at 10:27 AM, Peter Wemm <peter@wemm.org> wrote:
>>>>=20
>>>>> On Thu, Aug 8, 2013 at 12:04 AM, s m <sam.gh1986@gmail.com> wrote:
>>>>>> hello guys,
>>>>>>=20
>>>>>> i have a question about ip addresses. i know my question is not relat=
ed to
>>>>>> freebsd but i googled a lot and found nothing useful and don't know w=
here i
>>>>>> should ask my question.
>>>>>>=20
>>>>>> i want to know how can i calculate the number of ip addresses in a ra=
nge?
>>>>>> 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 calcul=
ate
>>>>>> the number of ip addresses for any range?
>>>>>>=20
>>>>>> i'm confusing about it. please help me to clear my mind.
>>>>>> thanks in advance,
>>>>>=20
>>>>> My immediate reaction is.. is this a homework / classwork / assignment=
?
>>>>>=20
>>>>> Anyway, you can think of it by converting your start and end addresses=

>>>>> to an integer.  Over simplified:
>>>>>=20
>>>>> $ cat homework.c
>>>>> main()
>>>>> {
>>>>> int start =3D  (192 << 24) | (0 << 16) | (0 << 8) | 1;
>>>>> int end =3D  (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
>>>>>=20
>>>>> The +1 is correcting for base zero. 192.0.0.1 - 192.0.0.2 is two
>>>>> usable addresses.
>>>>>=20
>>>>> I'm not sure what you want to do with the mask of 8.
>>>>>=20
>>>>> You can also do it with ntohl(inet_addr("address")) as well and a
>>>>> multitude of other ways.
>>>>=20
>>>>=20
>>>> Hold on a second, why would you correct the base zero ?
>>>> It can be a valid IP address.
>>>=20
>>> 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.
>>>=20
>>> --
>>=20
>> 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.
>>=20
>> -Kimmo
>=20
> If we go back to the orignal question: "if i have 192.0.0.1
> 192.100.255.254 how many ip addresses are available in this range?"
> They're all in the same 192.0.0.0/8.  Broadcast or sink addresses
> don't factor into it.
>=20
> --=20
> Peter Wemm - peter@wemm.org; peter@FreeBSD.org; peter@yahoo-inc.com; KI6FJ=
V
> UTF-8: for when a ' just won\342\200\231t do.
> <brueffer> ZFS must be the bacon of file systems. "everything's better wit=
h ZFS"

Peter,

The original question is "how to calculate a range", nobody said it should b=
e a /24, that was merely an example.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CE96AB08-2FB1-4892-A60B-AFF98121FF0B>