Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: server.c
- * Author: maxwell
- *
- * Created on April 20, 2011, 9:46 PM
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <arpa/inet.h>
- #include <sys/wait.h>
- #include <signal.h>
- int main(int argc, char** argv) {
- int sockfd; //Our socket
- int sum = 0;
- int i;
- int *recvbuff;
- struct addrinfo hints;
- struct addrinfo *servinfo;
- memset(&hints, 0, sizeof hints);
- hints.ai_family = AF_UNSPEC; // don't care IPv4 or IPv6
- hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
- hints.ai_flags = AI_PASSIVE; // fill in my IP for me
- if (getaddrinfo("vortex.labs.overthewire.org", "5842", &hints, &servinfo) != 0) {
- puts("Error getting address info for vortex.labs.overthewire.org");
- }
- sockfd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
- connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen);
- freeaddrinfo(servinfo);
- recvbuff = malloc(sizeof(unsigned int) * 4);
- for (i = 0; i < 4; i++) {
- recv(sockfd, recvbuff, 4, 0);
- sum += *(recvbuff + 0);
- memset(recvbuff, 0, sizeof(int));
- }
- send(sockfd, &sum, 16, 0);
- char *pass = malloc(100);
- recv(sockfd, pass, 100, 0);
- printf("%s\n", pass);
- close(sockfd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement