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

Michael Van Canneyt michael at freepascal.org
Thu Oct 12 22:15:25 CEST 2006



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.



More information about the fpc-pascal mailing list