SHARE
TWEET

Untitled

a guest Jun 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <arpa/inet.h>
  9. #include <netdb.h>
  10. #include <zconf.h>
  11.  
  12. struct email {
  13.     char *info;
  14.     char *from;
  15.     char *to;
  16.     char *subject;
  17.     char *message;
  18. };
  19.  
  20.  
  21.  
  22. int main( )
  23. {
  24.  
  25.     int sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  26.  
  27.     if (sockfd == -1) {
  28.         printf("Ha ocurrido un error\n");
  29.         exit(EXIT_FAILURE);
  30.     } else {
  31.         printf("Creado el socket\n");
  32.     }
  33.  
  34.     struct sockaddr_in dir;
  35.     dir.sin_family = AF_INET;
  36.     dir.sin_addr.s_addr = inet_addr("127.0.0.1");
  37.     dir.sin_port = htons(25);
  38.  
  39.  
  40.     if (connect(sockfd, (struct sockaddr*)&dir, sizeof(dir)) != 0) {
  41.         printf("Ha ocurrido un error al conectar\n");
  42.         exit(EXIT_FAILURE);
  43.     } else {
  44.         printf("Conectado al servidor\n");
  45.     }
  46.  
  47.  
  48.     char buff[500];
  49.     struct email email;
  50.  
  51.     read(sockfd, buff, sizeof(buff));
  52.     printf("%s\n", buff);
  53.  
  54.     int index = 4;
  55.     while(1) {
  56.         if (buff[index] == ' ') {
  57.             break;
  58.         }
  59.         index++;
  60.     }
  61.  
  62.  
  63.     strncpy(email.info, &buff[4], index - 4);
  64.     //printf("%s\n", email.info);
  65.     email.info = strdup(email.info);
  66.  
  67.  
  68.     bzero(buff, sizeof(buff));
  69.  
  70.  
  71.     strcat(buff, "HELO ");
  72.     strcat(buff, email.info);
  73.     strcat(buff, ".localnet\r\n");
  74.  
  75.     printf("%s\n", buff);
  76.  
  77.     write(sockfd, buff, sizeof(buff)); // envia nombre local
  78.  
  79.  
  80.     bzero(buff, sizeof(buff));
  81.     read(sockfd, buff, sizeof(buff));
  82.     printf("%s\n", buff);
  83.     // auth
  84.  
  85.     bzero(buff, sizeof(buff));
  86.     strcat(buff, "QUIT \r\n");
  87.     write(sockfd, buff, sizeof(buff)); // envia quit
  88.  
  89.  
  90.  
  91.     bzero(buff, strlen(buff));
  92.     //strcat(buff, "MAIL ");
  93.     //strcat(buff, "FROM:<carloscheca@dominio.com>\r\n");
  94.  
  95.     /*
  96.     sprintf(buff, "MAIL FROM:<carloscheca@dominio.com>\r\n");
  97.     printf("%s\n", buff);
  98.     write(sockfd, buff, strlen(buff)); // envia correo direccion
  99.      */
  100.  
  101.  
  102.     /*
  103.     bzero(buff, sizeof(buff));
  104.     strcat(buff, "RCPT TO:<profesorado@rysd.es>\r\n");
  105.     write(sockfd, buff, strlen(buff)); // envia correo direccion a enviar
  106.  
  107.     bzero(buff, sizeof(buff));
  108.     strcat(buff, "DATA \r\n");
  109.     write(sockfd, buff, sizeof(buff)); // envia data
  110.  
  111.     bzero(buff, sizeof(buff));
  112.     strcat(buff, "traza 3 \r\n.\r\n");
  113.     write(sockfd, buff, sizeof(buff)); // envia mensaje
  114.  
  115.  
  116.     bzero(buff, sizeof(buff));
  117.     strcat(buff, "QUIT \r\n");
  118.     write(sockfd, buff, sizeof(buff)); // envia quit
  119.  
  120.  
  121.  
  122.  
  123.     bzero(buff, sizeof(buff));
  124.     read(sockfd, buff, sizeof(buff));
  125.     printf("%s\n", buff);
  126.  
  127. */
  128.  
  129.     /*
  130.  
  131.  
  132.  
  133.  
  134.  
  135.     bzero(buff, sizeof(buff));
  136.     read(sockfd, buff, sizeof(buff));
  137.     printf("%s\n", buff);
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.     bzero(buff, sizeof(buff));
  146.     read(sockfd, buff, sizeof(buff));
  147.     printf("%s\n", buff);
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.     bzero(buff, sizeof(buff));
  155.     read(sockfd, buff, sizeof(buff));
  156.     printf("%s\n", buff);
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.     bzero(buff, sizeof(buff));
  165.     read(sockfd, buff, sizeof(buff));
  166.     printf("%s\n", buff);
  167. */
  168.  
  169.  
  170.     close(sockfd);
  171.  
  172.     return 0;
  173. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top