From owner-freebsd-net@FreeBSD.ORG Sat Aug 10 00:54:37 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 65800EDF for ; Sat, 10 Aug 2013 00:54:37 +0000 (UTC) (envelope-from ml@my.gd) Received: from mail-we0-f180.google.com (mail-we0-f180.google.com [74.125.82.180]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E6D052E0D for ; Sat, 10 Aug 2013 00:54:36 +0000 (UTC) Received: by mail-we0-f180.google.com with SMTP id p61so4085722wes.11 for ; Fri, 09 Aug 2013 17:54:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:from:subject:date:to; bh=8P3gfO7BlPaftX04hENdPoBPEbiFf1xhMc9fdmMFoic=; b=iiEKYdiB/10lf7aryWSlg8MumK/UdLg8cFeCmxG0yXavs2a0Du7n7FVa2rs5AfYbtb fzmqadmXdUAuK1bo7mJT9MfKOKhV52H4jtkTXntlLCtEKeyA0PKpeH633fSyQu5Cd52M +am2mdrNODTpNDJ4XB0vfB3kjxLCwG3c8Y2VbnhqV6Vw7rAtn/DHAcoNE5Nu3FRoTpGj xSkOmri89/Iw+UK3NMYYojnUFDDFGlhSAbWLi+vWEeGnArVmcfw0OMCRoPXfPhT1gLmO pqfSCBcUNv6jfn9Bit3/Y2GIlrFstxJ42v58vJaEnHjdE83Y2th+Kbpl5QiSZNHe4iYH z8/g== X-Gm-Message-State: ALoCoQkcOJ9I8aVM7T+2AuiXhpTk/XET5jr87mGoCqEFie6Y7PJ2Z/RKsc6iG3K1nEd9nTWcgRle X-Received: by 10.194.9.229 with SMTP id d5mr1689817wjb.66.1376096075133; Fri, 09 Aug 2013 17:54:35 -0700 (PDT) Received: from [10.51.25.177] (86.20.90.92.rev.sfr.net. [92.90.20.86]) by mx.google.com with ESMTPSA id v9sm5243325wiw.8.2013.08.09.17.54.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Aug 2013 17:54:34 -0700 (PDT) References: <8B53C542-5CC3-45E6-AA62-B9F52A735EE5@my.gd> Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-Id: X-Mailer: iPhone Mail (10B144) From: Damien Fleuriot Subject: Re: how calculate the number of ip addresses in a range? Date: Sat, 10 Aug 2013 02:52:55 +0200 To: Peter Wemm Cc: Kimmo Paasiala , s m , FreeBSD Net X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Aug 2013 00:54:37 -0000 On 10 Aug 2013, at 01:17, Peter Wemm wrote: > On Fri, Aug 9, 2013 at 4:07 PM, Kimmo Paasiala wrote:= >> On Sat, Aug 10, 2013 at 1:44 AM, Peter Wemm wrote: >>> On Fri, Aug 9, 2013 at 9:34 AM, Fleuriot Damien wrote: >>>>=20 >>>> On Aug 8, 2013, at 10:27 AM, Peter Wemm wrote: >>>>=20 >>>>> On Thu, Aug 8, 2013 at 12:04 AM, s m 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. > 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.=