Guest User

Untitled

a guest
May 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <arpa/inet.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int s = socket(AF_INET, SOCK_STREAM, 0);
  11. if(s < 0)
  12. {
  13. cout << "socket error" << endl;
  14. return 1;
  15. }
  16.  
  17. struct sockaddr_in addr;
  18. addr.sin_family = AF_INET;
  19. addr.sin_port = htons(80);
  20. addr.sin_addr.s_addr = inet_addr("91.198.174.225");
  21. if(connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0)
  22. {
  23. cout << "connect error" << endl;
  24. return 1;
  25. }
  26.  
  27. char msg[] = "GET /wiki/Maemo HTTP/1.1\nHost: ru.wikipedia.org\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5\nAccept: text/html\nConnection: close\n\n";
  28.  
  29. cout << "bytes send: " << send(s, msg, sizeof(msg), 0) << endl;
  30.  
  31. char buf_tmp[1024];
  32.  
  33. while(recv(s, buf_tmp, 1024, 0) > 0)
  34. cout << buf_tmp << endl;
  35.  
  36. // recv(s, buf_tmp, 1024, MSG_WAITALL);
  37. // cout << buf_tmp << endl;
  38.  
  39. close(s);
  40.  
  41. return 0;
  42. }
Add Comment
Please, Sign In to add comment