using System; using System.IO; using System.Net; using System.Net.Sockets; namespace nulldd { class nulldd { static void Main(string[] args) { int size; if ((args.Length != 2) || !int.TryParse(args[1], out size)) { Console.Error.WriteLine("usage: nulldd "); return; } byte[] zeros = new byte[1024 * 1024]; Array.Clear(zeros, 0, zeros.Length); Socket servsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); servsock.Bind(new IPEndPoint(IPAddress.Any, 6666)); servsock.Listen(512); servsock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); for (int round = 1; ; round++) { Socket client = servsock.Accept(); FileStream file = new FileStream(args[0], FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, zeros.Length, FileOptions.WriteThrough); for (int i = 0; i < size; i++) file.Write(zeros, 0, zeros.Length); file.Flush(); file.Close(); Console.WriteLine("#" + round); client.Close(); } } } }