#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>

#define VXWORKS
/* new style socket address */

struct bsd44_sockaddr_in {
	unsigned char  sin_len;
	unsigned char  sin_family;
	unsigned short sin_port;
	struct	  in_addr sin_addr;
	unsigned char  sin_zero[8];
};

/* Also see blaster.c -- the companion program */

void
blastee(int bytes_to_read, int howmany)
{
	int sock;
	struct bsd44_sockaddr_in sin;
	int ret;
	char buf[1460];
	int total = 0;
	int i;

	sock = socket(AF_INET, SOCK_DGRAM, 0);
	if (sock < 0) 
		exit(1);
	
	if (bytes_to_read == 0)
		bytes_to_read = 100;	/* default */
	if (howmany == 0)
		howmany = 1;	/* default */

	bzero(&sin, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(6666);
	sin.sin_addr.s_addr = 0;
	ret = bind(sock, &sin, sizeof(sin));
	if (ret < 0) {
		close(sock);
		exit(1);
	}
	setbuf(stdout, 0);
	for (i = 0; howmany == -1 || i < howmany; i++) {
		ret = recv(sock, buf, sizeof(buf), 0);
		if (ret < 0) {
			printf("recv: errno 0x%x\n",errnoGet());
			close(sock);
			exit(1);
		}
		printf(".");
	}
	close(sock);
	printf("blastee normal exit\n");
}

#ifndef VXWORKS
main()
{
	blastee();
}
#endif
