Getting broadcast IP or NetworkIP of a host

Getting broadcast IP or NetworkIP of a host

Post by Harsha » Wed, 08 Aug 2001 15:52:14



Hi all,

I'm writing a C++ program, where I want to get broadcast IP of the
machine I'm running it. Is there a function to do this?  or how can I
get this infomation?

Thanks in advance,
Harshana

 
 
 

Getting broadcast IP or NetworkIP of a host

Post by Barry Margoli » Fri, 10 Aug 2001 04:59:44




>I'm writing a C++ program, where I want to get broadcast IP of the
>machine I'm running it. Is there a function to do this?  or how can I
>get this infomation?

I don't think there's a function to do it.  To compute the broadcast
address of an interface, get its address and network mask.  The broadcast
address is then:

  (address & mask) | (INADDR_BROADCAST & !mask)

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. Getting the broadcast address for IP interface

Here's the scenario.  I am given an IP address, and told to send a UDP
packet to the broadcast.  I open the socket, and setsockopt to
SO_BROADCAST.  Now comes the tricky part.  How can I figure out the
broadcast address for the network specified in the given IP address?
I don't want to have my users plunking around with netmasks to figure
out which bits are set to 1.

I also realize that this is OS dependent (I believe) and may not be
portable.  So I'd appreciate seeing some examples to get me started.
I can always cruise through TFM once I figure out a good starting
point! :-)

As always, thanks in advance for any light you could shed on this
subject.

j
--
Jeffrey L. Bromberger -- Postmaster At Large -- ILX Systems, Inc.

+1.212.720.1024

2. partitions for mail and named?

3. Can't ping the host name or host IP address from host.

4. help installing g77 on SPARC 2 running RedHat LINUX 5.2?

5. can't ping host or host IP from host ?

6. Samba as a browse master in 2 networks

7. Broadcast through IP-IP tunnel - help!

8. Subscription

9. getting entire host name or ip address

10. getting a host ip name

11. rh6.2, changing IP address gets destination host unreachable

12. getting the ip addr of for the host

13. getting remote host ip from telnet and rlogin?