// This tiny program connects repeatedly to a server and sends patterns of garbage to it // Example: // garbage_tcp 127.0.0.1 22 10 1 10 1 // It stops when all patterns have been tried, or when connection is refused (server has shut down) #include #include #include #include #include #include #include static const char *server_addr="127.0.0.1"; static in_port_t server_port=7; static void send_it(const char *buf, size_t buflen) { int fd = socket(AF_INET,SOCK_STREAM,0); assert(fd>=0); struct sockaddr_in sa; memset(&sa,0,sizeof(sa)); sa.sin_family=AF_INET; sa.sin_addr.s_addr = inet_addr(server_addr); sa.sin_port = ntohs(server_port); if(connect(fd,(sockaddr*)(void*)&sa,(socklen_t)(sizeof(sa)))!=0) { printf("connect() failed, server is probably dead\n"); exit(EXIT_SUCCESS); } if(buflen!=0) { long tot_bytes=0; for(;;) { long bytes_written=write(fd,buf,buflen); if(bytes_written<=0) { printf("Connection closed after %ld bytes",tot_bytes); break; } tot_bytes+=bytes_written; } } close(fd); } static const uint8_t filldata[] = { 0, 1, 2, 0xfe, 0xff }; static void chunk_loop(size_t buflen, char *buf, size_t clen, uint8_t *c) { unsigned *c_idx=new unsigned[clen]; memset(c_idx,0,sizeof(unsigned)*clen); for(;;) { int i=clen-1; for(;;) { c_idx[i]++; if(c_idx[i] \n"); return EXIT_FAILURE; } server_addr = argv[1]; server_port=strtoul(argv[2],0,0); run(strtoul(argv[3],0,0), strtoul(argv[4],0,0), strtoul(argv[5],0,0), strtoul(argv[6],0,0)); return 0; }