SHARE
TWEET

Untitled

a guest Aug 12th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * File:   server.c
  3.  * Author: maxwell
  4.  *
  5.  * Created on April 20, 2011, 9:46 PM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <errno.h>
  12. #include <string.h>
  13. #include <sys/types.h>
  14. #include <sys/socket.h>
  15. #include <netinet/in.h>
  16. #include <netdb.h>
  17. #include <arpa/inet.h>
  18. #include <sys/wait.h>
  19. #include <signal.h>
  20.  
  21.  
  22.  
  23. int main(int argc, char** argv) {
  24.     int sockfd; //Our socket
  25.     int sum = 0;
  26.     int i;
  27.     int *recvbuff;
  28.     struct addrinfo hints;
  29.     struct addrinfo *servinfo;
  30.    
  31.     memset(&hints, 0, sizeof hints);
  32.     hints.ai_family = AF_UNSPEC;     // don't care IPv4 or IPv6
  33.     hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
  34.     hints.ai_flags = AI_PASSIVE;     // fill in my IP for me
  35.    
  36.     if (getaddrinfo("vortex.labs.overthewire.org", "5842", &hints, &servinfo) != 0) {
  37.         puts("Error getting address info for vortex.labs.overthewire.org");
  38.     }
  39.  
  40.     sockfd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
  41.     connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen);
  42.     freeaddrinfo(servinfo);
  43.  
  44.     recvbuff = malloc(sizeof(unsigned int) * 4);
  45.    
  46.     for (i = 0; i < 4; i++) {
  47.         recv(sockfd, recvbuff, 4, 0);
  48.         sum += *(recvbuff + 0);
  49.         memset(recvbuff, 0, sizeof(int));
  50.     }
  51.  
  52.     send(sockfd, &sum, 16, 0);
  53.     char *pass = malloc(100);
  54.     recv(sockfd, pass, 100, 0);
  55.     printf("%s\n", pass);
  56.     close(sockfd);
  57.     return 0;
  58. }
RAW Paste Data
Top