Networking Forums

Networking Forums > Computer Networking > Linux Networking > Can't read broadcast packets on Fedora 4

Reply
Thread Tools Display Modes

Can't read broadcast packets on Fedora 4

 
 
A. W. Dunstan
Guest
Posts: n/a

 
      01-11-2006, 08:04 PM
I've written a small piece of code to read packets broadcast to a given
port. It has worked on RH8 through FC3. I built it on FC4 and it blocks
at recvfrom(). It works on Ubuntu - I copied the executable over from the
FC4 machine (where it doesn't work) to the Ubuntu machine & it works just
fine there. I also recompiled on the Ubuntu machine & it still works.

The idea is that another program is broadcasting packets to port 3000, which
I then want to read. Tcpdump confirms that they really are being
broadcast, and are making it to the FC4 machine:

# tcpdump -p -vvvX -s 250 -c 2 dst port 3000
tcpdump: listening on eth0, link-type EN10MB (Ethernet),
capture size 250 bytes
15:42:45.632378 IP (tos 0x0, ttl 64, id 33248, offset 0, flags [DF], proto
17, length: 172) ironsides2.myinternal.domain.com.32833 >
192.168.254.255.3000: [udp sum ok] UDP, length 144
0x0000: 4500 00ac 81e0 4000 4011 39ec c0a8 fe23 E.....@.@.9....#
0x0010: c0a8 feff 8041 0bb8 0098 98d3 0401 0101 .....A..........
0x0020: c03e 2662 0090 0000 03b3 960f 03ee 0100 .>&b............
0x0030: 0101 00e1 0601 0102 0101 00e1 0601 0102 ................
0x0040: 0000 0000 8000 0000 0000 0000 4114 3db2 ............A.=.
0x0050: a2dc 7580 c153 343f 9c91 99aa 414d ac97 ..u..S4?....AM..
0x0060: 3cdd 55e2 3fd1 db45 bf69 64fb c048 51dd <.U.?..E.id..HQ.
0x0070: 0000 0000 0200 0000 0000 0000 0000 0000 ................
0x0080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0090: 0000 0000 0000 0000 0000 0000 0131 3032 .............102
0x00a0: 4531 3100 0000 0000 0000 0000 E11.........
15:42:45.700594 IP (tos 0x0, ttl 64, id 33249, offset 0, flags [DF], proto
17, length: 172) ironsides2.mynternal.domain.com.32833 >
192.168.254.255.3000: [udp sum ok] UDP, length 144
0x0000: 4500 00ac 81e1 4000 4011 39eb c0a8 fe23 E.....@.@.9....#
0x0010: c0a8 feff 8041 0bb8 0098 1a88 0401 0101 .....A..........
0x0020: c03f 634a 0090 0000 03b3 960f 03e9 0100 .?cJ............
0x0030: 0101 00e1 0601 0102 0101 00e1 0601 0102 ................
0x0040: 0000 0000 8000 0000 0000 0000 4114 56b8 ............A.V.
0x0050: 0d86 efa2 c153 3575 33e4 4f47 414d a92c .....S5u3.OGAM.,
0x0060: 6957 c1d9 3fd1 db42 bf65 4b12 4047 4b36 iW..?..B.eK.@GK6
0x0070: 0000 0000 0200 0000 0000 0000 0000 0000 ................
0x0080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0x0090: 0000 0000 0000 0000 0000 0000 0131 3034 .............104
0x00a0: 4631 3100 0000 0000 0000 0000 F11.........


The configurations are as follows:

FC4 machine:
g++ 4.0.2
kernel 2.6.14-1.1637

Ubuntu machine:
g++ 4.0.1
kernel 2.6.10-5-686

On both machines I compile as follows:
g++ -Wall -Wextra tst.cpp -o tst

There are no compilation errors or warnings. Stripped of it's error
checking the code looks like this:

int localPort = 3000;
char m_bfr[8192];

int m_localSocket = socket(AF_INET, SOCK_DGRAM, 0);

int enable(1);
int len(sizeof(int));
int sts = setsockopt(m_localSocket, SOL_SOCKET, SO_BROADCAST,
&enable, len);
sts = setsockopt(m_localSocket, SOL_SOCKET, SO_REUSEADDR,
&enable, len);

// Bind m_localSocket to localPort.
struct sockaddr_in inname;
inname.sin_addr.s_addr = INADDR_ANY;
inname.sin_family = AF_INET;
inname.sin_port = htons(localPort);
bind(m_localSocket, (const sockaddr *)&inname, sizeof(inname)))


// Now read something.
struct sockaddr_in from;
unsigned int fromlen(sizeof(sockaddr_in));
int bytesRead = recvfrom(m_localSocket, m_bfr, m_maxBfrSize, 0,
(sockaddr *)&from, &fromlen);


On the FC4 machine t runs fine (no error returns anywhere), and blocks on
the recvfrom. I'm at a loss as to why it blocks when there _are_ packets
on the net, and other machines _can_ read them. The executable also runs
under RH8 running under Windows VMWare.

Any suggestions as to why this is so, or what I can do about it would be
greatly appreciated.

Thanks!


--
Al Dunstan, Software Engineer
OptiMetrics, Inc.
3115 Professional Drive
Ann Arbor, MI 48104-5131
 
Reply With Quote
 
 
 
 
Moe Trin
Guest
Posts: n/a

 
      01-12-2006, 11:13 PM
On Wed, 11 Jan 2006, in the Usenet newsgroup comp.os.linux.networking, in
article <(E-Mail Removed)> , A. W. Dunstan wrote:

>I've written a small piece of code to read packets broadcast to a given
>port. It has worked on RH8 through FC3. I built it on FC4 and it blocks
>at recvfrom(). It works on Ubuntu - I copied the executable over from the
>FC4 machine (where it doesn't work) to the Ubuntu machine & it works just
>fine there.


OK - code is unlikely to be at fault

>The idea is that another program is broadcasting packets to port 3000, which
>I then want to read. Tcpdump confirms that they really are being
>broadcast, and are making it to the FC4 machine:


netstat -tupan

Is your port actually listening on the right interface and accepting
packets from the world (or at least the right network)?

/sbin/iptables -L

It there a _firewall_ running on this box that is blocking stuff?

>Any suggestions as to why this is so, or what I can do about it would be
>greatly appreciated.


Well, my coding skills are classed as "dire emergency only", so I can't
talk to your program, but the firewall problem is fairly common. If that's
not the answer, hopefully some one else will have an answer.

Old guy
 
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why sending packets to broadcast IP? news@celticbear.com Linux Networking 2 06-26-2008 04:18 PM
Broadcast packets in C killua Linux Networking 4 06-06-2007 08:58 PM
Getting SMB broadcast packets to Virtual Machine Larry Finger Linux Networking 2 05-01-2006 11:58 PM
block broadcast packets from routing Dave Lister Linux Networking 1 09-16-2003 08:01 PM
Netgear HE102 and broadcast packets Joey Wireless Internet 2 07-05-2003 03:21 AM



1 2 3 4 5 6 7 8 9 10 11