[fpc-pascal] [NETWORK - LINUX ]: Calculate broadcast - network

TOUZEAU DAVID david.touzeau at fr.kaspersky.com
Tue Oct 17 17:10:26 CEST 2006


<message>
</message>
Excuse me Michael for this late....

Your answers are very good and answer to my need..Many many thanks

for others :
-----------------------
use Sockets;
../..
var
    A,N : cardinal;   IA : in_addr;ib : in_addr;
  begin

  a:=StrToHostAddr('10.1.1.34').s_addr;  // Get IP in longint
  n:=StrToHostAddr('255.255.0.0').s_addr;
  ia.s_addr:=a and n;
  writeln('Network ->',HostAddrToStr(ia));
  ia.s_addr:=a or not n;
   writeln('broadcast ->',HostAddrToStr(ia));

Michael Van Canneyt a écrit :
> On Thu, 12 Oct 2006, Michael Van Canneyt wrote:
>
>   
>> On Thu, 12 Oct 2006, TOUZEAU DAVID wrote:
>>
>>     
>>> <message>
>>> </message>
>>>
>>> Dear
>>>
>>> The tool is designed to simplify the change network settings quickly.
>>>
>>> So the goal for the admin is to type:
>>>
>>> #./tool 192.168.1.2 255.255.255.0 192.168.1.1
>>>
>>> and the tool will change settings in /etc/network/interfaces by
>>>
>>> iface eth0 inet static
>>>         address 192.168.1.2
>>>         netmask 255.255.255.0
>>>         network 192.168.xx.0
>>>         broadcast 192.168.xx.255
>>>         gateway 192.168.1.1
>>>
>>>       
>> Use the sockets unit:
>>
>> Var
>>   sa,sn,nw,bc : string;
>>   A,N : cardinal;
>>   IA : in_addr; // in sockets unit.
>>   
>>
>> a:=StrToHostAddr(sa).s_addr;  // Get IP in longint
>> n:=StrToHostAddr(sn).s_addr;  // Get Netmask in longint.
>> nw:=a and N;                  // Network.
>> bc:=A and not N;              // broadcast
>> ia.s_addr:=a and N;           // Calculate network
>> nw:=HostAddrToStr(ia);        // Convert to string
>> ia.s_addr:=a and not N;       // Calculate broadcast
>>     
>
> This should be 
> ia.s_addr:=a or not N; 
>
> My apologies.
>
>   

-- 

    * 01.41.39.04.42
    * 06.20.56.74.33
    * ICQ:160018849
    * Skype:dtouzeau

    * Site technique destiné aux entreprises:
      http://entreprises.kaspersky.fr
    * Inscrivez-vous dès maintenant dans l'espace partenaires !
      <http://partners.kaspersky.fr>

(Retrouvez sur ces sites des faqs, tutoriaux, Forums et liens de 
téléchargement de la gamme Buiness Optimal)

 




* *

 





More information about the fpc-pascal mailing list