Title: Broadcasting own IP across entire network
Tags: c++;c;sockets;networking;broadcast
Question: I am wondering if there is a simpler way to broadcast my own IP to all devices on my network on a specific port using C or C++
I don't know too much about socket programming just cause most of my applications don't need a network.  I looked into it and I found one piece of code that looks promising although it doesn't exactly broadcast since it sends to specific IP addresses.
Is there a way to broadcast to addresses say between 151.154.11.224/255 in one fell swoop or do I need to go through loop through the addresses and then send a packet to them myself?
EDIT: I'm asking about c++ implementation, not network infrastructure.  That is why I linked the above link.
Comment: Yes, broadcasting is built into the TCP/IP stack, you should have found thousands of examples if you just searched a little.

Comment: When I searched, [this link](http://www.tcpipguide.com/free/t_MessageAddressingandTransmissionMethodsUnicastBroa.htm) was one of the first that came up. I searched for the terms *tcp broadcast* (but note that broadcasting is not supported using TCP, it's really unicast only but you can accomplish the same using *multicast*).

Comment: Looping through all the possible IP addresses on the LAN wouldn't be much fun on a class A network :)

Comment: I did, I didn't find much.  Care to be a little more specific on what to search for b/c I guess I didn't search for the right thing

Comment: ....okay.  I learned I'll just use UDP then.  Thx for the help

Comment: Oh man that looks freaky

Here is the accepted answer: Send a UDP datagram to the broadcast address of the network. The UDP datagram will contain the origin IP address. Other apps in the network can obtain "your" IP address from the UDP datagram.
Is there a way to broadcast to addresses say between 151.154.11.224/255 in one fell swoop or do I need to go through loop through the addresses and then send a packet to them myself?
In every IP network there is an address, known as broadcast address, to which all devices in a network are enabled to receive datagrams. Further information can be found here: http://en.wikipedia.org/wiki/Broadcast_address
I'm asking about c++ implementation, not network infrastructure. That is why I linked the above link.
This example might be helpful:
https://www.cs.rutgers.edu/~pxk/417/notes/sockets/udp.html
Comment for this answer: Note : Sending to broadcast address might often need CAP_NET_ADMIN (or atleast CAP_NET_BROADCAST) capabilities (normally super user - but possible to set perms using sudo). And as @Baqs already pointed above - it'd be possible for UDP only.
Comment for this answer: Thanks! You seem to be the only one that understood the issue.
Comment for this answer: Glad this was helpful!

Here is another answer: This is pretty much what IP multicast was invented for.
Edit 0:
Ton of examples on the internet. Just a couple for you:
using boost asio,
using plain sockets in C.
Many more out there, but if you are any serious about doing network programming, get this book and you'll never regret.
Comment for this answer: Unfortunately, you can't do much network programming without understanding at least *some* of its infrastructure.
Comment for this answer: I'm more so asking about implementation.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:05/01/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++><c><sockets><networking><broadcast>', 'Title': 'Broadcasting own IP across entire network', 'ViewCount': 1484, 'id': 29980435, 'user_AboutMe': '<p>Currently a C/C++ firmware engineer (PPC)</p>\n\n<p>I work with NXPs line of ARM microcontrollers in my spare time.</p>\n\n<p>Former positions include Analog circuit designer and C/C++ software engineer</p>\n\n<p>Other things I pretend to know include PCB design, Power supply design, and Python scripts.</p>\n', 'user_AccountId': 1402006.0, 'user_DisplayName': 'Funkyguy', 'user_Reputation': 606.0, 'user_Views': 253.0, 'user_id': 1330595.0}}