Re: IP/subnet function in C.
From: Per Hedeland (per_at_hedeland.org)
Date: 01/30/05
- Next message: Kris Kennaway: "Re: pkg_add"
- Previous message: Gustavo Cipriano Mota Sousa: "Setting support for accents in syscons"
- In reply to: Dmitry Mityugov: "Re: IP/subnet function in C."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Kris Kennaway: "Re: pkg_add"
- Previous message: Gustavo Cipriano Mota Sousa: "Setting support for accents in syscons"
- In reply to: Dmitry Mityugov: "Re: IP/subnet function in C."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|