Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-10

[NETWORK - LINUX ]: Calculate broadcast - network

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

TOUZEAU DAVID

<message>
</message>
Dear

I develop a tool that change the network settings in /etc/network/interfaces

the config file must be
iface eth0 inet static
address 192.168.xx.xx
netmask 255.255.255.0
network 192.168.xx.0
broadcast 192.168.xx.255
gateway 192.168.xx.xx

In this case when user type 10.1.1.2 and 255.255.0.0 i need to calculate the network address and broadcast.

Where can i found a function that return the good answer ? Is there somebody has developped a such function ?

David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6 FreePascal-Lazarus,perl,delphi,php icq:160018849
Wolfe, Robert
to TOUZEAU DAVID

The network IP and the broadcast address are usually determined by your IT department if they are static addresses or automatically assigned by the DHCP server on your network, if one is present.

Robert Wolfe, MCSE/RHCE,
Survey Research and Data Acquisition Resource
Department of Health Behavior; Roswell Park Cancer Institute

________________________________

Earlier message 35 lines
From: on behalf of TOUZEAU DAVID Sent: Thu 10/12/2006 9:46 AM To: Subject: [fpc-pascal] [NETWORK - LINUX ]: Calculate broadcast - network <message> </message> Dear I develop a tool that change the network settings in /etc/network/interfaces the config file must be iface eth0 inet static address 192.168.xx.xx netmask 255.255.255.0 network 192.168.xx.0 broadcast 192.168.xx.255 gateway 192.168.xx.xx In this case when user type 10.1.1.2 and 255.255.0.0 i need to calculate the network address and broadcast. Where can i found a function that return the good answer ? Is there somebody has developped a such function ? -- David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6 FreePascal-Lazarus,perl,delphi,php icq:160018849
Alexandre Leclerc
to TOUZEAU DAVID: <message> </message> Dear I develop a tool that change the network settings in…

2006/10/12, TOUZEAU DAVID :

Show quoted text 17 lines
<message> </message> Dear I develop a tool that change the network settings in /etc/network/interfaces the config file must be iface eth0 inet static address 192.168.xx.xx netmask 255.255.255.0 network 192.168.xx.0 broadcast 192.168.xx.255 gateway 192.168.xx.xx In this case when user type 10.1.1.2 and 255.255.0.0 i need to calculate the network address and broadcast.

For a class b network (based on your mask) that would be 10.1.255.255 for the broadcast and probably be 10.1.0.0 (?) for the network. More info there: http://en.wikipedia.org/wiki/Broadcast_address

But all this is good for private networks only.

Hope this helps;
Best regards.
Alexandre Leclerc
TOUZEAU DAVID
to Wolfe, Robert: The network IP and the broadcast address are usually determined by your IT department if…

<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

And set /etc/ini.d/networking reload.

Just need this.

best regards

David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6 FreePascal-Lazarus,perl,delphi,php icq:160018849
Michael Van Canneyt
to TOUZEAU DAVID
TOUZEAU DAVID wrote 20 lines
<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
bc:=HostAddrToStr(ia);        // Convert to string.

Michael.

Michael Van Canneyt
to Michael Van Canneyt
Michael Van Canneyt wrote 40 lines
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.

TOUZEAU DAVID
to Michael Van Canneyt

<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 wrote 50 lines
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) * *