//======================================================== file = blast.c ===== //= A simple program to "blast" UDP packets = //= - Be careful of IP_ADDR (default should be 127.0.0.1) = //============================================================================= //= Notes: = //= 1) This program conditionally compiles for Winsock and BSD sockets. = //= Set the initial #define to WIN or BSD as appropriate. = //= 2) There is *no* error checking in this program. Error checking was = //= omitted to simplify the program. = //= 3) Must manually set IP_ADDR, MESS_SIZE, and N. = //= 4) Computed data rate does not consider packet headers = //=---------------------------------------------------------------------------= //= Build: bcc32 blast.c or cl blast.c wsock32.lib for Winsock = //= gcc blast.c -lsocket -lnsl for BSD = //=---------------------------------------------------------------------------= //= History: KJC (06/02/06) - Genesis (from client1.c) = //= KJC (02/21/07) - Added some timing = //============================================================================= #define WIN // WIN for Winsock and BSD for BSD sockets //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for memcpy() and strcpy() #ifdef WIN #include // Needed for all Winsock stuff #include // Needed for ftime() and timeb structure #endif #ifdef BSD #include // Needed for system defined identifiers. #include // Needed for internet address structure. #include // Needed for socket(), bind(), etc... #include // Needed for inet_ntoa() #include // Needed for ftime() and timeb structure #include // Needed for sockets stuff #include // Needed for sockets stuff #endif //----- Defines --------------------------------------------------------------- #define PORT_NUM 1050 // Port number used #define IP_ADDR "127.0.0.1" // IP address to blast to #define MESS_SIZE 1024 // Message size #define N 100000 // Number of times to send message //===== Main program ========================================================== void main(void) { #ifdef WIN WORD wVersionRequested = MAKEWORD(1,1); // Stuff for WSA functions WSADATA wsaData; // Stuff for WSA functions #endif unsigned int my_s; // My (client1) socket descriptor struct sockaddr_in dest_addr; // Server Internet address unsigned int addr_len; // Internet address length char out_buf[MESS_SIZE]; // Buffer for output data struct timeb start, stop; // Start and stop times structures double elapsed; // Elapsed time in seconds double data_rate; // Computed data rate in Mb/s unsigned int i; // Loop counter #ifdef WIN // This stuff initializes winsock WSAStartup(wVersionRequested, &wsaData); #endif // Create a socket and fill in destination address information my_s = socket(AF_INET, SOCK_DGRAM, 0); dest_addr.sin_family = AF_INET; // Address family to use dest_addr.sin_port = htons(PORT_NUM); // Port num to use dest_addr.sin_addr.s_addr = inet_addr(IP_ADDR); // IP address to use // Load the output buffer for (i=0; i