All pastes #406950 Raw Edit

Someone

public text v1 · immutable
·published 2007-03-22 20:24 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/un.h>
#include <sys/socket.h>
#include <netinet/udp.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <netdb.h>


int sock_setup(void) {
	int sfd, error, slen;
	struct sockaddr_in saddr;
	struct hostent* h;
	char* adr = "69.55.233.82";	
	int hport = 5842;	
	char* host = "vortex.labs.pulltheplug.org";
	sfd = socket(PF_INET, SOCK_STREAM, 0);
	if(sfd < 0) {
		perror("SOCKET");
		exit(0);
	}

	h = gethostbyname(host);
	
	if(h  == NULL) {
		perror("GETHOSTBYNAME");
		exit(0);
	}	

	printf("Host Name: %s\n", h->h_name);
 	unsigned int i = 0;
	while(h->h_addr_list[i] != NULL) {
		printf("IP   Addr: %s\n", inet_ntoa(h->h_addr_list[0]));
	i++;
	}


	memset(&saddr, 0, sizeof(saddr));
	saddr.sin_family = AF_INET;
	saddr.sin_port = htons(hport);
	saddr.sin_addr.s_addr = inet_addr(adr);

	error = connect(sfd, (struct sockaddr *)&saddr, sizeof(saddr));
	if(error < 0) {
		perror("CONNECT");
		exit(0);
	}	
	
	return sfd;
}


int main(int argc, char* argv[]) {
	int sfd, size;
	unsigned int buf[4];
	unsigned int a,b,c,d;
	sfd = sock_setup();
	char* strbuf;

	size = recv(sfd, &buf, 16, 0);
	if(size < 0) {
		perror("RECV");
		exit(0);
	}
unsigned int i = 0;

while(i < 4) {
	printf(":%u\n", buf[i]);
i++;
}
	unsigned int final = buf[0] + buf[1] + buf[2] + buf[3];
	
	size = send(sfd, &final, sizeof(final), 0);
	if(size < 0) {
		perror("SEND");
		exit(0);
	}
	
	size = recv(sfd, &buf, 4096, 0);
	if(size < 0) {
		perror("RECV2");
		exit(0);
	}
	printf("buf:%s\n", strbuf);
	

	exit(1);
}