[123] in bugtraq
Re: udp packet storms
daemon@ATHENA.MIT.EDU (Tim Newsham)
Sun Oct 30 22:01:04 1994
From: newsham@zang.kcc.hawaii.edu (Tim Newsham)
To: perry@imsi.com
Date: Sun, 30 Oct 1994 16:00:06 -1000 (HST)
Cc: bugtraq@fc.net
In-Reply-To: <9410301638.AA00366@snark.imsi.com> from "Perry E. Metzger" at Oct 30, 94 11:38:29 am
>
>
> To my knowledge, the broadcast trick will not work -- the "broadcast"
> will not go out on the ethernet or other broadcast address because the
> broadcast socket option will not have been selected and the packet
> will not be broadcast in reply. The echo loop between two hosts might,
> of course...
>
> Perry
Run the following program. Try "[name] 255.255.255.255" and
"[name] X.X.X.255" (assuming 8 bit subnetting). Notice both
will work properly although I did not do a setsockopt with
SO_BROADCAST.
Tim N.
/* echo.c - [name] [ip address] */
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
int hosts = 0;
im_done()
{
printf("Done. %d hosts responded\n", hosts);
exit(0);
}
error(str)
char *str;
{
perror(str);
exit(1);
}
main(argc, argv)
char **argv;
{
int s, adlen, val;
char *message = "Echo Test", *remote;
char buf[128];
struct sockaddr_in ad;
if(argc > 1)
remote = argv[1];
else
remote = "127.0.0.1";
signal(SIGINT, im_done);
s = socket(AF_INET, SOCK_DGRAM, 0);
if(s < 0)
error("socket");
ad.sin_family = AF_INET;
ad.sin_addr.s_addr = inet_addr(remote);
ad.sin_port = htons(7);
if(sendto(s, message, strlen(message), 0, &ad, sizeof(ad)) < 0)
error("sendto");
printf("Echo Test. SIGINT to quit.\n");
adlen = sizeof(ad);
while(recvfrom(s, buf, 128, 0, &ad, &adlen) > 0) {
printf("Reply from %s: %s\n", inet_ntoa(ad.sin_addr), buf);
hosts++;
}
}