Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UDP Broadcast Size Limit

156 views
Skip to first unread message

DON BERRYMAN

unread,
Sep 13, 1993, 4:37:38 PM9/13/93
to
I am attempting to BROADCAST UDP DATAGRAMS to all
nodes, from a HP735 HPUX9.01 The following code
does that for packets less that are less than
4328 bytes but gives the following error:

$ cc -o udp udp.c
$ udp
Sending 4320
Sent 4320
Sending 4328
udp: Message too long
udp: unable to send request

If I change server.sin_addr.s_addr to INADDR_ANY
then I do not get this error but can only receive
the data on the local node.

It seems that there is a limit on the size UDP
Broadcasts. Is it possible to up this limit on my
node? Or have I reached a limit in the actual UDP
definition that I can not work around?

My goal is to broadcast 4700 byte packets 32 times
per second. I know this is 150kbytes/second and
might seriously degrade (or even kill) the local
ethernet but I am not incharge of system
specification.

==========================================================

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <signal.h>
#include <netdb.h>

extern int errno;
int sock; /* socket descriptor */
struct sockaddr_in server; /* for local socket address */

handler()
{
signal(SIGALRM, handler);
}

main(argc, argv)

int argc;
char *argv[];

{
int i;
int k, j, size;
char buffer[10000];

sock = socket (AF_INET, SOCK_DGRAM, 0);
if (sock == -1) {
perror(argv[0]);
fprintf(stderr, "%s: unable to create socket\n", argv[0]);
exit(1);
}

i = 1;
k = setsockopt (sock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i));

server.sin_family = AF_INET;
server.sin_port = 1456;

/* server.sin_addr.s_addr = INADDR_ANY; */ /* If used packets larger than 4328 can be sent locally */
server.sin_addr.s_addr = INADDR_BROADCAST; /* If used packets smaller than 4328 can be broadcasted to all nodes */

signal(SIGALRM, handler); /* Set up alarm signal handler. */

size = 4320;
for (i=1 ; i<200 ; ++i) {

fprintf(stdout, "Sending %i \n", size);

k = sendto (sock, &buffer, size, 0, &server, sizeof(server));

if (k == -1) { perror(argv[0]);
fprintf(stderr, "%s: unable to send request\n", argv[0]);
exit(1);
}

fprintf(stdout, " Sent %i \n", k);

alarm(1);
pause();
size = size + 8;

}
}

Don Berryman
Defence Research Establishment Pacific
Canadian Forces Base Esquimalt
Victoria, BC, CANADA, V0S-1B0
604-363-2731 604-363-2856fax
berr...@orca.drep.dnd.ca

Oliver Laumann

unread,
Sep 14, 1993, 9:18:33 AM9/14/93
to
BERR...@orca.drep.dnd.ca (DON BERRYMAN) writes:
> It seems that there is a limit on the size UDP
> Broadcasts. Is it possible to up this limit on my node?

The size of UDP broadcast datagrams is usually limited by the
MTU of the network interface you are using, because broadcast
datagrams are not fragmented. The MTU of ethernet interfaces,
for instance, is typically 1500 (see netstat -i); I don't think
you can increase this value.


By the way, your code can be improved a bit in a couple of places:

> server.sin_family = AF_INET;
> server.sin_port = 1456;

This should read

server.sin_port = htons(1456);

or your program won't work on machines with host byteorder != network
byteorder.

> /* server.sin_addr.s_addr = INADDR_ANY;
> server.sin_addr.s_addr = INADDR_BROADCAST;

I don't think that using INADDR_ANY or INADDR_BROADCAST as the address
for broadcasts datagrams is a good idea (unless it's a test program).
You can't control which interface is used on a multi-homed machine
(besides, INADDR_BROADCAST doesn't work correctly in some UNIX versions).

A better solution is to obtain the interface list (by means of the
SIOCGIFCONF ioctl) and use the broadcast address of the interface
connecting to the network to which you want to send the broadcast
packets.

W. Richard Stevens

unread,
Sep 14, 1993, 10:47:16 AM9/14/93
to
>> It seems that there is a limit on the size UDP
>> Broadcasts. Is it possible to up this limit on my node?

Most Berkeley-derived implementations prohibit the fragmentation of a
broadcast datagram. There's no technical reason, it's just a common
sense decision they made way back. If you *really* don't mind the
performance implications, and have the sources, it's trivial to change;
just remove the following test in netinet/ip_output.c:

/* don't allow broadcast messages to be fragmented */
if ((u_short)ip->ip_len > ifp->if_mtu) {
error = EMSGSIZE;
goto bad;
}

Rich Stevens (rste...@noao.edu)

Eric Evans x3364 (gardner)

unread,
Sep 14, 1993, 1:07:23 PM9/14/93
to
BERR...@orca.drep.dnd.ca (DON BERRYMAN) writes:

>I am attempting to BROADCAST UDP DATAGRAMS to all
>nodes, from a HP735 HPUX9.01 The following code
>does that for packets less that are less than
>4328 bytes but gives the following error:

>$ cc -o udp udp.c
>$ udp
>Sending 4320
> Sent 4320
>Sending 4328
>udp: Message too long
>udp: unable to send request

.
.


.
>It seems that there is a limit on the size UDP
>Broadcasts. Is it possible to up this limit on my
>node? Or have I reached a limit in the actual UDP
>definition that I can not work around?

On SunOS and SCO UNIX, at least, I have sent (*not broadcast*) UDP
datagrams of sizes up to 16000 octets. UDP merely slaps on a header
and passes this monster to IP, which segments it to fit over the local
Ethernet.

However, to allow this I have had to change a kernel parameter the sets
a limit on the largest block of data that can be passed from the user
process to the OS via a socket or TLI call. Each version of UNIX (or
other OS) may do this in a different way, if it is even allowed. If
this limit is exceeded by a given datagram, then the send call returns
an error. I don't know about HPUX, though.

As for BROADCASTING, when I try to broadcast a datagram larger than
the Ethernet MTU, my socket/TLI call throws it away and doesn't even
return an error (at least on SCO UNIX). If you think about it, it
doesn't make much sense to broadcast something larger than the LAN
MTU, since it's the LAN itself that provides the broadcast capability.
IP simply uses the local LAN's broadcast mechanism (if it has one)
whenever it needs to send a message to the IP broadcast address.

Hope this helps

-------------------------------------------------------------------------
Eric Evans ev...@titan.tsd.arlut.utexas.edu
Applied Research Laboratory
University of Texas at Austin

Jim Robinson

unread,
Sep 14, 1993, 4:31:20 PM9/14/93
to
Oliver Laumann (n...@cs.tu-berlin.de) wrote:

>I don't think that using INADDR_ANY or INADDR_BROADCAST as the address
>for broadcasts datagrams is a good idea (unless it's a test program).
>You can't control which interface is used on a multi-homed machine
>(besides, INADDR_BROADCAST doesn't work correctly in some UNIX versions).

Under SunOS 4.1.1 it certainly did seem (to my surprise) that
INADDR_BROADCAST did not work. I traced the packet making its way to the
recipient hosts, but apparently being discarded by the IP layer. Assuming
I did not screw my testing up, why would Sun #define INADDR_BROADCAST when
it doesn't work? Hasn't the use of 0xffffffff as a broadcast address been
around long enough to expect that even a not-quite-current version of
SunOS such as 4.1.1 should do the right thing?

>A better solution is to obtain the interface list (by means of the
>SIOCGIFCONF ioctl) and use the broadcast address of the interface
>connecting to the network to which you want to send the broadcast
>packets.

I eventually did use the broadcast address of the appropriate interface
and, voila, worked like a charm.
--
Jim Robinson
robi...@mdd.comm.mot.com
{ubc-cs!van-bc,uunet}!mdivax1!robinson

0 new messages