Re: IP/subnet function in C.

From: Per Hedeland (per_at_hedeland.org)
Date: 01/30/05


Date: Sun, 30 Jan 2005 10:32:03 +0000 (UTC)


[ Top-posting corrected ]

In article <ctibii$1ged$1@news.peterlink.ru> "Dmitry Mityugov"
<_my_first_name_._my_last_name_@myrealbox.com> writes:

>sam wrote:

>> I want to extract the subnet (192.168.3.0) from ip address 192.168.3.21
>> Is there a C function I can use to do that? I don't want to reinvent the
>> wheel if it is already exist in the C std lib.

>Take a look at internet address manipulation routines, expecially
>inet_netof() and inet_lnaof().

Just be aware that those functions are basically obsolete, since they
assume the old hardwired class A/B/C scheme of network/host separation.
Might be OK for the 192.168 case, but in general you need to know the
netmask in use to do the operation correctly. (And then it's just a
matter of bitwise ANDing address and mask once you have them in integer
form, of course.)

--Per Hedeland
per@hedeland.org



Relevant Pages

  • Re: permission system
    ... I know that but I dont want to reinvent the wheel:) ... just a matter of preference. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Bareword errors?
    ... reinvent the wheel when the wheel is right infront of you ready to be ... You claim you want full control over how the form data is processed yet ...
    (comp.lang.perl.misc)
  • Re: Somerset and Dorset tears
    ... turn ourselves around in circles to reinvent the wheel. ... We have had the Commission on Integrated Transport ...
    (uk.railway)
  • Re: Embedded OSD (Not STV5370A)
    ... >>would not reinvent the wheel, unless it is a project to learn about. ... been messing with video and image processing for too many years. ...
    (comp.arch.embedded)
  • Re: [OT] .NET Rant
    ... Obviously, if you have to reinvent the wheel, the built in classes are ... The lazy programmer would use what is built in. ...
    (microsoft.public.dotnet.languages.csharp)