duncan_roe, thanks for looking into this.
sendaddr is used only for binding purpose. recvaddr is used for sending the packets using sendto().
Main Topics
Browse All TopicsHi, here is a code in which we are trying to send a simple broadcast packet to all the computers on the network. But this is not working properly. The sender and receiver programs seem to get struck inside sendto and recvfrom functions respectively.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ok I see DEST_ADDR now. But I think you should use the Broadcast Address for your network, as ifconfig will give you:
19:01:31$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:76:6D:BC:E1
inet addr:10.255.255.1 Bcast:10.255.255.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38790 errors:0 dropped:0 overruns:0 frame:0
TX packets:38520 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8229514 (7.8 Mb) TX bytes:3361119 (3.2 Mb)
Interrupt:16
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:139 errors:0 dropped:0 overruns:0 frame:0
TX packets:139 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:137520 (134.2 Kb) TX bytes:137520 (134.2 Kb)
The broadcast address for my LAN is 10.255.255.255
Most problems where in receiver code:
1) You should use htons() to defind sin_port port numbers
2) You don't have to use gethostname() when using IP address. Moreover you shouldn't use any predefined source IP address in the receiver.
3) Most impotent, you should 'bind' before 'recvfrom'
In sender code is also slightly fixed.
Working code is in attachment.
Business Accounts
Answer for Membership
by: duncan_roePosted on 2008-01-11 at 01:47:22ID: 20635109
I don't think you want the sending address to be INADDR_ANY - I would think the broadcast address for the network would be more appropriate. You could hard-code it for testing (i.e. inet_addr(hardcoded dotted address)) and write the code to figure out what it is later.