UDP Broadcasting

UDP Broadcasting

Post by Keit » Wed, 09 Jun 1999 04:00:00



I've been trying, without success, to get one machine to send a UDP
broadcast and another machine on the network to read it.  I can get the
two machines to talk to each other via UDP when one is sending messages
directly to the other (not broadcasting).  I can also see the packets on
the receiver machine using snoop.

I would have thought something similar to the following would have
worked..

Broadcaster:

char buffer[80];
int send_size, optval = 1;
union sock
{
      struct sockaddr s;
      struct sockaddr_in i;

Quote:}    remote_addr;

sd = socket (AF_INET, SOCK_DGRAM, 0);

setsockopt (sd, SOL_SOCKET, SO_BROADCAST, (const void *) &optval,
sizeof(optval));

remote_addr.i.sin_family = AF_INET;
remote_addr.i.sin_port = htons (PORT_NUMER);
remote_addr.i.sin_addr.s_addr = inet_addr ("###.###.###.255");

/* While you don't have to call connect for UDP, doing so allows you */
/* to send packets without specifying the IP address with each send. */

connect (sd, &remote_addr.s, sizeof(struct sockaddr));

send_size = sprintf (buffer, "Whatever");
send (sd, buffer, send_size, 0);

Receiver

sd = socket (AF_INET, SOCK_DGRAM, 0);

local_addr.i.sin_family = AF_INET;
local_addr.i.sin_port = htons (PORT_NUMBER);
local_addr.i.sin_addr.s_addr = htonl (INADDR_BROADCAST);

bind (sd,  &local_addr.s, sizeof (struct sockaddr));

remote_addr.i.sin_family = AF_INET;
remote_addr.i.sin_port = htons (PORT_NUMER);
remote_addr.i.sin_addr.s_addr = inet_addr (BROADCASTERS_IP_ADDR);

connect (sd, &remote_addr.s, sizeof(struct sockaddr));

recv (sd, buffer, size, 0);

Any ideas why this doesn't work?  Can anyone provide source that does
work?

 
 
 

UDP Broadcasting

Post by Michael Kruege » Wed, 09 Jun 1999 04:00:00


Did you try not to call connect() but to use recvfrom() for the receiver
instead?

Michael.

Keith schrieb:

Quote:> I've been trying, without success, to get one machine to send a UDP
> broadcast and another machine on the network to read it.  I can get
> the two machines to talk to each other via UDP when one is sending
> messages directly to the other (not broadcasting).  I can also see the
> packets on the receiver machine using snoop.

> I would have thought something similar to the following would have
> worked..

> Broadcaster:

> char buffer[80];
> int send_size, optval = 1;
> union sock
> {
>       struct sockaddr s;
>       struct sockaddr_in i;
> }    remote_addr;

> sd = socket (AF_INET, SOCK_DGRAM, 0);

> setsockopt (sd, SOL_SOCKET, SO_BROADCAST, (const void *) &optval,
> sizeof(optval));

> remote_addr.i.sin_family = AF_INET;
> remote_addr.i.sin_port = htons (PORT_NUMER);
> remote_addr.i.sin_addr.s_addr = inet_addr ("###.###.###.255");

> /* While you don't have to call connect for UDP, doing so allows you
> */
> /* to send packets without specifying the IP address with each send.
> */

> connect (sd, &remote_addr.s, sizeof(struct sockaddr));

> send_size = sprintf (buffer, "Whatever");
> send (sd, buffer, send_size, 0);

> Receiver

> sd = socket (AF_INET, SOCK_DGRAM, 0);

> local_addr.i.sin_family = AF_INET;
> local_addr.i.sin_port = htons (PORT_NUMBER);
> local_addr.i.sin_addr.s_addr = htonl (INADDR_BROADCAST);

> bind (sd,  &local_addr.s, sizeof (struct sockaddr));

> remote_addr.i.sin_family = AF_INET;
> remote_addr.i.sin_port = htons (PORT_NUMER);
> remote_addr.i.sin_addr.s_addr = inet_addr (BROADCASTERS_IP_ADDR);

> connect (sd, &remote_addr.s, sizeof(struct sockaddr));

> recv (sd, buffer, size, 0);

> Any ideas why this doesn't work?  Can anyone provide source that does
> work?


 
 
 

UDP Broadcasting

Post by Fletcher Glen » Thu, 10 Jun 1999 04:00:00


Would the sender and receiver be on different sub-nets?  Routers
will not forward broadcast packets.

--
                Fletcher Glenn


> I've been trying, without success, to get one machine to send a UDP
> broadcast and another machine on the network to read it.  I can get
> the two machines to talk to each other via UDP when one is sending
> messages directly to the other (not broadcasting).  I can also see the
> packets on the receiver machine using snoop.

> I would have thought something similar to the following would have
> worked..

> Broadcaster:

> char buffer[80];
> int send_size, optval = 1;
> union sock
> {
>       struct sockaddr s;
>       struct sockaddr_in i;
> }    remote_addr;

> sd = socket (AF_INET, SOCK_DGRAM, 0);

> setsockopt (sd, SOL_SOCKET, SO_BROADCAST, (const void *) &optval,
> sizeof(optval));

> remote_addr.i.sin_family = AF_INET;
> remote_addr.i.sin_port = htons (PORT_NUMER);
> remote_addr.i.sin_addr.s_addr = inet_addr ("###.###.###.255");

> /* While you don't have to call connect for UDP, doing so allows you
> */
> /* to send packets without specifying the IP address with each send.
> */

> connect (sd, &remote_addr.s, sizeof(struct sockaddr));

> send_size = sprintf (buffer, "Whatever");
> send (sd, buffer, send_size, 0);

> Receiver

> sd = socket (AF_INET, SOCK_DGRAM, 0);

> local_addr.i.sin_family = AF_INET;
> local_addr.i.sin_port = htons (PORT_NUMBER);
> local_addr.i.sin_addr.s_addr = htonl (INADDR_BROADCAST);

> bind (sd,  &local_addr.s, sizeof (struct sockaddr));

> remote_addr.i.sin_family = AF_INET;
> remote_addr.i.sin_port = htons (PORT_NUMER);
> remote_addr.i.sin_addr.s_addr = inet_addr (BROADCASTERS_IP_ADDR);

> connect (sd, &remote_addr.s, sizeof(struct sockaddr));

> recv (sd, buffer, size, 0);

> Any ideas why this doesn't work?  Can anyone provide source that does
> work?

 
 
 

1. udp broadcast forwarding

Hello

I want to forward udp broadcasts across network.
example :

on eth0
i have bcast 192.1.2.255 on port 1234
and i want redirect udp packets
on eth1 192.1.3.255 on port 1234

the host is a redhat linux "firewall"

do you have any idea ??
thanks

2. www doesn't look nice

3. UDP broadcast server-client example.

4. DEVFS and Rights

5. code needed for UDP broadcast

6. howto mount a CD-ROM with special permissions

7. UDP Broadcasts Doesn't ?????

8. kdelib compiler error

9. UDP broadcasting & multiple interfaces

10. UDP broadcast

11. udp broadcasting over ppp interface

12. UDP Broadcasting

13. UDP Broadcast?