rendered paste body#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include <stdlib.h>#include <errno.h>//#include <netinet/tcp.h>void trocas(unsigned char **host,unsigned char **file,unsigned char *hostEfile);void criar_pedido(unsigned char **dest,unsigned char *url);int main (int argc,char *argv[]) { int s; //int len; struct sockaddr_in sbase; //struct tcp_info status; s=socket(AF_INET,SOCK_STREAM,0); sbase.sin_family=AF_INET; sbase.sin_port=htons(80); sbase.sin_addr.s_addr=inet_addr("127.0.0.1"); memset(&sbase.sin_zero,0x00,8); if (connect(s,(struct sockaddr *)&sbase,sizeof(sbase)) == -1) { printf("%s\n",strerror(errno)); exit(0); } //len=sizeof(status); //getsockopt(s,SOL_TCP,TCP_INFO,&status,&len); if (argc<2) exit(0); unsigned char *pkt; criar_pedido(&pkt,argv[1]); send(s,pkt,strlen(pkt)+1,0); //printf("%s\n",pkt); return 0;}void criar_pedido(unsigned char **dest,unsigned char *url) { unsigned char *host=NULL,*file=NULL; if (strchr(url,'/')) trocas(&host,&file,url); else { host=calloc(strlen(url)+1,1); strcpy(host,url); file=calloc(2,1); *file='/'; } *dest=malloc(83+strlen(url)); sprintf(*dest, "GET %s HTTP/1.0\r\n" "User-Agent: dvd/0.1\r\n" "Accept: */*\r\n" "Host: %s\r\n" "Connection: Keep-Alive\r\n\r\n" ,file,host);}void trocas(unsigned char **host,unsigned char **file,unsigned char *hostEfile) { unsigned int x; for(x=0;*(hostEfile+x) != '/';x++); *host=calloc(x,1); memcpy(*host,hostEfile,x); *file=calloc(strlen(hostEfile)-x,1); memcpy(*file,hostEfile+x,strlen(hostEfile)-x);}