#include #include #include #include #include #include char data[20480]; /******************************************************* test tool to send UDP packets up to 20480 in size to a port send_udp host port packets packetsize Useful for network load tests, UDP throughput *******************************************************/ main(int argc,char *argv[]) { int sock,ii,port_no,packets,packetsize; struct sockaddr_in name; struct hostent *hp; if ((argv[1] == NULL) || (argv[2] == NULL) || (argv[3] == NULL) || (argv[4] == NULL)) { printf("usage: %s host port packets packetsize\n",argv[0]); } hp = gethostbyname(argv[1]); if (hp == 0) { fprintf(stderr,"%s: unknown host\n",argv[1]); exit(1); } port_no = atoi(argv[2]); packets = atoi(argv[3]); packetsize = atoi(argv[4]); sock = socket(AF_INET,SOCK_DGRAM,0); if (sock < 0) { perror("opening datagram socket"); exit(1); } name.sin_family = AF_INET; name.sin_addr.s_addr = INADDR_ANY; name.sin_port = 0; if (bind(sock,(struct sockaddr *)&name,sizeof(name)) < 0) { perror("binding datagram socket"); exit(1); } bcopy((char *)hp->h_addr,(char *)&name.sin_addr,hp->h_length); name.sin_family = AF_INET; name.sin_port = htons(port_no); for (ii = 0; ii < packets; ii++) { if (sendto(sock,data,packetsize,0,(struct sockaddr *)&name,sizeof(name)) < 0) { perror("sending datagram message"); } } close(sock); exit(0); }