All pastes #819872 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-12-17 06:44 UTC
rendered paste body
#include <sys/select.h>
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(void)
{
        int sockfd,nbytes;
        struct hostent *host;
        struct sockaddr_in proxy;
        char buff[40];

        struct one
        {
                uint8_t ver,nmethod,method[255];
        } ssend1;

        ssend1.ver=5;
        ssend1.nmethod=1;
        ssend1.method[0]=0;

        struct two
        {
                unsigned char ver,method;
        } srecv1;

        host=gethostbyname("123.232.108.98");
        proxy.sin_family = AF_INET;
        proxy.sin_port = htons(1080);
        proxy.sin_addr = *((struct in_addr *)host->h_addr);
        memset(proxy.sin_zero,'\0',sizeof(proxy.sin_zero));

        printf("socket\n");
        if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0) {
                perror("socket");
                exit(1);
        }
        printf("connect \n");
        if(connect(sockfd,(struct sockaddr *)&proxy,sizeof(proxy)) < 0){
                perror("connect");
                exit(EXIT_FAILURE);
        }
        printf("sync.. \n");
        if((nbytes=send(sockfd, &ssend1, 3,0)) < 0)             {
                        perror("send");
                        exit(EXIT_FAILURE);
        }
        printf("sent nbytes: %i\n", nbytes);
        printf("now recv..\n");
        if((nbytes = recv(sockfd, &srecv1, 50, 0))<0)           {
                perror("recv");
                exit(EXIT_FAILURE);
        }
        printf("got %i\n",nbytes);
        printf("ver: %i\nmethod:%i\n",srecv1.ver,srecv1.method);
        struct hostent *host2;
        host2 = gethostbyname("69.55.233.83");
        proxy.sin_addr=*((struct in_addr *)host2->h_addr);
        proxy.sin_port=htons(24027);
        printf("%s\n",host2->h_name);
        char buf1[50];
        struct request {
                uint8_t v;
                uint8_t c;
                uint8_t r;
                uint8_t at;
                uint32_t ipa;
                uint16_t p;
        } __attribute__((packed));

        struct request myreq,myreq2;

        myreq.v = 0x05;
        myreq.c = 0x01;
        myreq.r = 0x00;
        myreq.at = 0x01;
        memcpy(&myreq.ipa, &proxy.sin_addr, 4);
        memcpy(&myreq.p, &proxy.sin_port, 2);

        printf("%i\n",myreq.p);
        int i = 0;


        if ((nbytes = send(sockfd, &myreq, sizeof(myreq), 0)) < 0){
                perror("send() request");
                return -1;
        }
        printf("sent\n");
        printf(":%i\n", nbytes);
        if ((nbytes = recv(sockfd,&myreq2,10,0))<0) {
                perror("recv");
                exit(EXIT_FAILURE);
        }

        printf("received : %d\n",nbytes);

        char buf[1024];
        memset(&buf, 0, 1024);

        printf("waiting for semtex stuff\n");
        fd_set rfds;
        int m = sockfd +1;
        struct timeval tv;
        tv.tv_sec = 15;
        tv.tv_usec = 0;
        FD_ZERO(&rfds);
        FD_SET(sockfd, &rfds);
        int r = 0;
        if ((r = select(m, &rfds, NULL, NULL, &tv)) < 0) {
                perror("select");
                exit(-1);
        }
        if ((nbytes = recv(sockfd, &buf, 1024, 0)) < 0) {
                perror("recv\n");
                exit(-1);
        }
        printf("got %d\n", nbytes);
        printf("%s\n", buf);

        exit(1);
}