LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-06-2009, 08:16 PM   #1
linux_newbie79
Member
 
Registered: Apr 2009
Posts: 36

Rep: Reputation: 15
broadcast fails


HI,

The following broadcast client code fails and I need your help to fix this issue. It fails in sendto with errno set to 101(Network Unreachable).

Herewith attached the code and ifconfig of my system.

#ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:FB4:32
inet addr:192.168.108.221 Bcast:192.168.108.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefb:d432/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:510744 errors:0 dropped:0 overruns:0 frame:0
TX packets:441083 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:77840573 (74.2 MiB) TX bytes:81657829 (77.8 MiB)
Interrupt:185 Base address:0x1400

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1957 errors:0 dropped:0 overruns:0 frame:0
TX packets:1957 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2333868 (2.2 MiB) TX bytes:2333868 (2.2 MiB)

#route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.108.0 * 255.255.255.0 U 0 0 0 eth0


int main(int argc, char *argv[])
{
struct sockaddr_in destaddr;
int port = 31000;
char *msg = "TEST_MSG";
int msglen = strlen(msg);
int ret, numbytes;
int sockfd;
int broadcastflag = 1;

/* do getopt and get the value */
destaddr.sin_family = AF_INET;
destaddr.sin_port = htons(port);
destaddr.sin_addr.s_addr = INADDR_BROADCAST;

/* create socket */
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
printf("create socket failed\n");
exit(1);
}

/* set sock options */
ret = setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcastflag, sizeof(broadcastflag));
if (ret < 0)
{
printf("setsockopt failed\n");
exit(1);
}

/* send the message */
numbytes = sendto(sockfd, msg, msglen, 0, (struct sockaddr *)&destaddr, sizeof(destaddr));
if (numbytes != msglen)
{
printf("sendto failed bytes %d errno: %d\n", numbytes, errno);
exit(1);
}
close(sockfd);
return 0;
}
 
Old 10-07-2009, 09:30 PM   #2
Papatux
LQ Newbie
 
Registered: Aug 2006
Posts: 1

Rep: Reputation: 0
The gateway address cannot be "192.168.108.0" that address is the network ID for that subnet and is not a valid address. The gateway can be "192.168.108.1". I'm not sure how your interface config is created (manualy or DHCP) but you will need to correct that before going any further.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TV broadcast davholla General 1 10-20-2006 02:16 PM
Broadcast without broadcast Mammuth Linux - Networking 1 10-01-2006 04:58 PM
Encrypted Reiserfs Fails to Mount -- Reiserfsck Fails as Well antic Linux - Hardware 0 07-30-2004 04:32 PM
What is a broadcast ip? snocked Linux - Newbie 7 01-28-2003 09:56 AM
What does Broadcast mean? BHanrahan Linux - Newbie 3 09-03-2002 12:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration