From 979eca0095ecfb40a160636752eaf0e61bdc4ca9 Mon Sep 17 00:00:00 2001 From: Choupom Date: Thu, 17 Mar 2011 17:38:30 +0100 Subject: refactored packetgen --- src/tools/packetgen.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/tools/packetgen.cpp (limited to 'src/tools/packetgen.cpp') diff --git a/src/tools/packetgen.cpp b/src/tools/packetgen.cpp new file mode 100644 index 00000000..7d11ed26 --- /dev/null +++ b/src/tools/packetgen.cpp @@ -0,0 +1,36 @@ +/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ +/* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include + +enum { NUM_SOCKETS = 64 }; + +int Run(NETADDR Dest) +{ + NETSOCKET aSockets[NUM_SOCKETS]; + + for(int i = 0; i < NUM_SOCKETS; i++) + { + NETADDR BindAddr = {NETTYPE_IPV4, {0}, 0}; + aSockets[i] = net_udp_create(BindAddr); + } + + while(1) + { + unsigned char aData[1024]; + int Size = 0; + int SocketToUse = 0; + io_read(io_stdin(), &Size, 2); + io_read(io_stdin(), &SocketToUse, 1); + Size %= 256; + SocketToUse %= NUM_SOCKETS; + io_read(io_stdin(), aData, Size); + net_udp_send(aSockets[SocketToUse], &Dest, aData, Size); + } +} + +int main(int argc, char **argv) +{ + NETADDR Dest = {NETTYPE_IPV4, {127,0,0,1}, 8303}; + Run(Dest); + return 0; +} -- cgit 1.4.1