All pastes #631947 Raw Edit

Miscellany

public text v1 · immutable
#631947 ·published 2007-07-24 14:12 UTC
rendered paste body
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>

#define DEST_PORT 5842
#define DEST_IP "69.55.233.82"

int main(void)
{
        int sockfd;
        struct sockaddr_in dest_addr;

        sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!

        dest_addr.sin_family = AF_INET;          // host byte order
        dest_addr.sin_port = htons(DEST_PORT);   // short, network byte order
        dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
        memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);

        connect(sockfd, (struct sockaddr *)&dest_addr, sizeof dest_addr);

        unsigned int num1 = 0;
        recv(sockfd, (char *) &num1, 4, 0);

        unsigned int num2 = 0;
        recv(sockfd, (char *) &num2, 4, 0);

        unsigned int num3 = 0;
        recv(sockfd, (char *) &num3, 4, 0);

        unsigned int num4 = 0;
        recv(sockfd, (char *) &num4, 4, 0);

        printf("Numbers:\nnum1:\t%d\nnum2:\t%d\nnum3:\t%d\nnum4:\t%d\n", num1, num2, num3, num4);

        int res = num1 + num2 + num3 + num4;
        char *msg;
        sprintf(msg, "%d", res);
        send(sockfd, msg, strlen(msg), 0);
        char *stuff;
        recv(sockfd, (char *) &stuff, 1024, 0);
        printf("Readed: %s\n", stuff);

        close(sockfd);
        return 0;
}