Bug 10101 - INADDR_BROADCAST does not work for broadcast messages
Summary: INADDR_BROADCAST does not work for broadcast messages
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: kernel
Version: 6.1
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Michael K. Johnson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-03-10 01:53 UTC by Ron Weigel
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2000-05-22 15:40:36 UTC
Embargoed:


Attachments (Terms of Use)

Description Ron Weigel 2000-03-10 01:53:47 UTC
The following code gives ENETUNREACH on RedHat 6.1 but works on other
versions of Linux:

#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define SOCKET_ERROR -1
#define closesocket close
typedef int SOCKET;
typedef struct sockaddr SOCKADDR;
typedef struct sockaddr_in SOCKADDR_IN;
#define FALSE 0
#define TRUE 1

int sendbroadcast(int sendport, const char* sendbuf, int sendbytes)
{
  SOCKET s;

  if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == SOCKET_ERROR)
    return errno;

  int err = 0;

  int optval = TRUE;
  if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<const char*>
(&optval), sizeof(optval)) == SOCKET_ERROR)
    err = errno;
  else
  {
    SOCKADDR_IN sockAddr;
    memset(&sockAddr, 0, sizeof(sockAddr));

    sockAddr.sin_family = AF_INET;
    sockAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
    sockAddr.sin_port = htons(sendport);

    int flags = 0;
    int bytes = sendto(s, sendbuf, sendbytes, flags,
reinterpret_cast<SOCKADDR*>(&sockAddr), sizeof(sockAddr));

    if (bytes == SOCKET_ERROR)
      err = errno;
  }
  closesocket(s);

  return err;
}

Comment 1 Jeff Johnson 2000-05-14 21:06:59 UTC
This smells like a kernel problem, so I'm changing the component.
What kernel are you using?

Comment 2 Cristian Gafton 2000-05-22 15:40:59 UTC
assigned to dledford

Comment 3 Alan Cox 2000-08-08 20:10:02 UTC
This depends solely on routing setup



Note You need to log in before you can comment on or make changes to this bug.