title: Receiving UDP broadcast packets on Linux
body: <p>We have existing software that periodically broadcasts UDP packets to a specific port (7125) on the local subnet (x.x.x.255). We have monitoring software running on HP-UX (11.11) that is able to receive these packets no problem. However, after porting the monitoring software to Linux (RHEL 6.1) we have found that it does not receive the broadcast packets. tcpdump shows the packets arriving at the Linux host, but the kernel does not send them through to our software.</p>
  
  <p>I've been using a couple of python 2.x scripts that mimic the socket API calls the monitoring software uses to test different scenarios. The Linux kernel passes the packets to the receiver software if the sender uses unicast (10.1.0.5), but not broadcast (10.1.0.255). I've been searching the web for several days and have not found anyone with the same problem. Any ideas?</p>
  
  <p>receiver.py</p>
  
  <pre><code>from __future__ import print_function
  import socket
  
  localHost = ''
  localPort = 7125
  remoteHost = '10.1.0.5'
  remotePort = 19100
  
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  s.bind((localHost, localPort))
  s.connect((remoteHost, remotePort))
  print('Listening on {0}:{1} for traffic from {2}:{3}'.format(localHost, localPort, remoteHost, remotePort))
  data = s.recv(1024)
  print('Received: {0}'.format(data))
  s.close()
  </code></pre>
  
  <p>sender.py</p>
  
  <pre><code>from __future__ import print_function
  import socket
  import time
  
  localHost = ''
  localPort = 19100
  remoteHost = '10.1.0.255'
  remotePort = 7125
  
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
  s.bind((localHost, localPort))
  s.connect((remoteHost, remotePort))
  data = 'sending this from {0}:{1} to {2}:{3}'.format(localHost, localPort, remoteHost, remotePort)
  print(data)
  print('2')
  time.sleep(1)
  print('1')
  time.sleep(1)
  s.send(data)
  print('sent at {0}'.format(time.ctime()))
  s.close()
  </code></pre>