Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 17.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5. #include <netinet/in.h>
  6. #include <arpa/inet.h>
  7. #include <sys/socket.h>
  8. #include <sys/types.h>
  9.  
  10. #define FILE_PHP "index.php"
  11. #define FILE_XML "data.xml"
  12. #define MAX_BUF 500
  13. #define VERO 1
  14. #define FALSO 0
  15.  
  16.  
  17. int port_store; /* usata per ricevere/inviare file */
  18. int port_general = 21; /* port_general, usata per la connessione principale */
  19.    
  20. /* Principali :) */
  21. void install(void); /* permette di installare il CMS */
  22. void inet_nexus (struct sockaddr_in*, const in_addr_t, const int); /* permette di impostare i dati per la connessione */
  23. void my_send (int, const char*, const char*); /* permette di inviare dati al server */
  24. void my_recv (int, const int); /* permette di ricevere i dati dal server */
  25. void format (char []); /* formatta il testo rivecuto dal server */
  26. void store (const int, const char*); /* invia il file al server */
  27. void update (FILE *, int, char [], char [], char [], struct tm*, char []); /* aggiorna il file xml con i nuovi dati */
  28.    
  29.  
  30. /* install --> */ void data_xml_func (FILE *); /* permette di creare il file data.xml */
  31. /* install --> */ void index_php_func (FILE *); /* permette di salvare il file index.php */
  32. /* add_new_article ---> */ void retrv (int, char[]); /* usata per il download dei file */
  33.  
  34.  
  35. void add_new_article (void); /* aggiunge nuovi articoli al blog */
  36.  
  37. int main (void)
  38. {
  39.     int scelta;
  40.     fprintf (stdout, "\t\tFutaro CMS - Admin\t\t\n\n");
  41.     fprintf (stdout, "1 = Installa Futaro CMS sul tuo web!\n");
  42.     fprintf (stdout, "2 = Inserisci un nuovo articolo sul tuo Futaro CMS\n");
  43.     fprintf (stdout, "3 = Esci, semplicmente!\n");
  44.     fprintf (stdout, "? = ");
  45.     fscanf (stdin, "%d", &scelta);
  46.     switch (scelta) {
  47.         case 1: install (); break;
  48.         case 2: add_new_article (); break;
  49.         case 3: exit (EXIT_SUCCESS);
  50.         default: fprintf (stderr, "Errore nell'inserimento del numero!\n"); exit (EXIT_FAILURE);
  51.     }
  52.     return 0;
  53. }
  54.  
  55.  
  56. void install()
  57. {
  58.     FILE *data_xml, *index_php; /* usati per gli stream dei due file necessari per il funzionamento del CMS */
  59.     char ip[20]; /* necessario per collegarsi all' FTP */
  60.     char username[20]; /* necessario per accedere all' FTP */
  61.     char password[20]; /* necessario per accedere all' FTP */
  62.     struct sockaddr_in info_general, info_store; /* struttura usata per impostare la connessione */
  63.     int sockfd_general, sockfd_store; /* stream socket */
  64.      
  65.     /* creo ed apro i file */
  66.     index_php = fopen (FILE_PHP, "w");
  67.     data_xml = fopen (FILE_XML, "w");
  68.    
  69.     /* se trovo qualche errore, avvisa ed esci */
  70.     if (index_php == NULL || data_xml == NULL) {
  71.         fprintf (stderr, "Errore nell'apertura del file!\n");
  72.         exit (EXIT_FAILURE);
  73.     }
  74.    
  75.     /* scrivi nel file data.xml */
  76.     data_xml_func (data_xml);
  77.                
  78.     /* scrivi nel file index.php */    
  79.     index_php_func (index_php);
  80.    
  81.     /* chiudi i file prcedentemente aperti */
  82.     fcloseall ();
  83.    
  84.     printf ("Inserisci il tuo IP es: xx.xx.xx.xx : ");
  85.     scanf ("%s", ip);
  86.    
  87.     printf ("Inserisci il tuo username: ");
  88.     scanf ("%s", username);
  89.    
  90.     printf ("Inserici la tua password: ");
  91.     scanf ("%s", password);
  92.  
  93.     /* imposto lo stream socket e controllo eventuali errori */
  94.     sockfd_general = socket (AF_INET, SOCK_STREAM, 0);
  95.     if (sockfd_general < 0)
  96.     {
  97.         fprintf (stderr, "Errore nella creazione del socket!\n");
  98.         exit(EXIT_FAILURE);
  99.     }
  100.    
  101.     /* inizializzo la connessione */
  102.     inet_nexus (&info_general, inet_addr(ip), port_general);
  103.    
  104.     /* mi connetto all'host e controllo se ci sono errori */
  105.     if ( (connect (sockfd_general, (struct sockaddr *) &info_general, sizeof (struct sockaddr_in) ) ) < 0)
  106.     {
  107.         fprintf (stderr, "Erorre nella connessione al server!\n" \
  108.                          "Controlla se si ha impostato correttamente l'ip, l'username ed infine la password\n");
  109.         exit (EXIT_FAILURE);
  110.     }
  111.     /*invio dati */
  112.     my_recv (sockfd_general, FALSO);
  113.     my_send (sockfd_general, "USER", username);
  114.     my_recv (sockfd_general, FALSO);
  115.     my_send (sockfd_general, "PASS", password);
  116.     my_recv (sockfd_general, FALSO);
  117.     my_send (sockfd_general, "MKD", "blog");
  118.     my_recv (sockfd_general, FALSO);
  119.     my_send (sockfd_general, "CWD", "blog");
  120.     my_recv (sockfd_general, FALSO);
  121.     my_send (sockfd_general, "TYPE", "I");
  122.     my_recv (sockfd_general, FALSO);
  123.     my_send (sockfd_general, "PASV", "");
  124.     my_recv (sockfd_general, VERO);
  125.    
  126.     /* connetto alla nuova porta, inizializzando i dati */
  127.     sockfd_store = socket (AF_INET , SOCK_STREAM, 0);
  128.     if (sockfd_store < 0)
  129.     {
  130.         fprintf (stderr, "Errore nella creazione del socket!\n");
  131.         exit (EXIT_FAILURE);
  132.     }
  133.    
  134.     inet_nexus (&info_store, inet_addr(ip), port_store);
  135.    
  136.     if ( (connect (sockfd_store, (struct sockaddr *) &info_store, sizeof (struct sockaddr_in) ) ) < 0)
  137.     {
  138.         fprintf(stderr, "Errore nella connessione al server!\n");
  139.         exit (EXIT_FAILURE);
  140.     }
  141.    
  142.     /* ora che è aperta una nuova connessione, posso inviare il file, non prima però di dirlo al server! */
  143.    
  144.     fprintf (stdout, "\n[+] File creati con successo\n[+]Inizio ad inviare il file\n");
  145.     /* adesso, invia il file: DATA.XML */
  146.     my_send (sockfd_general, "STOR", FILE_XML);
  147.     my_recv (sockfd_general, FALSO);
  148.    
  149.     store (sockfd_store, FILE_XML);
  150.     my_recv (sockfd_general, FALSO);
  151.     close (sockfd_store);
  152.    
  153.     fprintf(stdout, "[+] %s spedito con successo\n[+]Inizio ad inviare il file\n", FILE_XML);
  154.    
  155.    
  156.     /* ripetiamo la stessa cosa con il file: INDEX.PHP */
  157.     my_send (sockfd_general, "PASV", "");
  158.     my_recv (sockfd_general, VERO);
  159.    
  160.     /* connetto alla nuova porta, inizializzando i dati */
  161.     sockfd_store = socket (AF_INET , SOCK_STREAM, 0);
  162.     if (sockfd_store < 0)
  163.     {
  164.         fprintf (stderr, "Errore nella creazione del socket!\n");
  165.         exit (EXIT_FAILURE);
  166.     }
  167.    
  168.     inet_nexus (&info_store, inet_addr(ip), port_store);
  169.    
  170.     if ( (connect (sockfd_store, (struct sockaddr *) &info_store, sizeof (struct sockaddr_in) ) ) < 0)
  171.     {
  172.         fprintf(stderr, "Errore nella connessione al server!\n");
  173.         exit (EXIT_FAILURE);
  174.     }
  175.     my_send (sockfd_general, "STOR", FILE_PHP);
  176.     my_recv (sockfd_general, FALSO);
  177.     store (sockfd_store, FILE_PHP);
  178.     my_recv (sockfd_general, FALSO);
  179.     close (sockfd_store);
  180.     fprintf(stdout, "[+] %s spedito con successo!\n", FILE_PHP);
  181.     /* esco dall'FTP e chiudo */
  182.     my_send (sockfd_general, "QUIT", "");
  183.     my_recv (sockfd_general, FALSO);
  184.     close (sockfd_general);
  185.     fprintf(stdout, "L'installazione e' avvenuta correttamente.\nGrazie per aver intallato, Futaro CMS\n\n");
  186.     fprintf(stdout, "Il tuo blog e' raggiungibile al tuo indirizzo aggiungendo un /blog\n");
  187.     remove(FILE_PHP);
  188.     remove(FILE_XML);
  189.     return;
  190. }
  191.  
  192. void store (int sockfd, const char * nome_file)
  193. {
  194.     int size;
  195.     char *buffer;
  196.     FILE *pag = fopen (nome_file, "r");
  197.     if (pag == NULL)
  198.     {
  199.         fprintf(stderr, "Errore, nell'aprire il file %s, Assicurati di non averlo cancellato o spostato." \
  200.                         "Ri-avvia l'installazione\n", nome_file);
  201.         exit (EXIT_FAILURE);
  202.     }
  203.     /* ossento la dimensione del file */
  204.     fseek (pag, 0, SEEK_END);
  205.     size = ftell (pag);
  206.     rewind (pag);
  207.    
  208.     buffer = calloc(1, sizeof (char) * (size + 1) ); /* alloco un buffer da contenere tutti i caratteri del file */
  209.     if (buffer == NULL)
  210.     {
  211.         fprintf(stderr, "Scusa, ma non puoi inserire più articoli, lo spazio e\' insufficiente\n");
  212.         exit (EXIT_FAILURE);
  213.     }
  214.     /* leggo il testo e lo invio */
  215.    
  216.     fread (buffer, size, 1, pag);
  217.     write (sockfd, buffer, strlen (buffer) );
  218.    
  219.     /* chiudo tutto */
  220.     free(buffer);
  221.     fclose (pag);
  222.     close (sockfd);
  223.     return;
  224. }
  225.  
  226. void format (char testo[])
  227. {
  228.     int p1, p2;
  229.     int virgole = 0;
  230.     char *frase;
  231.     frase = strtok (testo, ",)");
  232.     while (frase != NULL)
  233.     {
  234.         virgole += 1;
  235.         if (virgole == 5) {
  236.             p1 = atoi (frase);
  237.             break;
  238.         }
  239.         frase = strtok (NULL, ",)");
  240.     }
  241.     frase = strtok (NULL, ")");
  242.     p2 = atoi (frase);
  243.     port_store = p1*256+p2; /* assegno la nuova porta per il trasferimento dei file */
  244.     return;
  245. }
  246.  
  247. void my_recv (int stream, const int bool)
  248. {
  249.     char buffer[MAX_BUF];
  250.     /* azzero il buffer ad ogni chiamata */
  251.     memset (buffer, 0, MAX_BUF);
  252.     read (stream, buffer, MAX_BUF);
  253.     if (bool)
  254.         format (buffer);
  255.     return;
  256. }
  257.  
  258. void my_send (int stream, const char* comando, const char* dato)
  259. {
  260.     char buffer[MAX_BUF];
  261.     /* azzero il buffer ad ogni chiamata */
  262.     memset (buffer, 0, MAX_BUF);
  263.     /* l'invio deve essere così formattato: COMANDO dato \r\nSYST\r\n */
  264.     /* copio dentro buffer, prima il comando e poi aggiungo il dato, e poi \r\nSYST\r\n */
  265.     sprintf (buffer, "%s %s\r\n", comando, dato);
  266.     write (stream, buffer, strlen (buffer) );
  267.     return;
  268. }
  269.  
  270. void inet_nexus (struct sockaddr_in *data, const in_addr_t ip, const int port)
  271. {
  272.     data->sin_family = AF_INET;
  273.     data->sin_port = htons (port);
  274.     data->sin_addr.s_addr = (unsigned long) ip;
  275.     return;
  276. }
  277.  
  278. void data_xml_func (FILE *database)
  279. {
  280.     time_t raw_time; /* usata per prelevare l'ora */
  281.     struct tm *time_s; /* usata per poter stampare singoli pezzi della data */
  282.     time (&raw_time); /* prelevo il tempo */
  283.     time_s = localtime (&raw_time); /* prelevo la data */
  284.     fprintf (database, "<\?xml version=\"1.0\" encoding=\"utf-8\"\?>\n" \
  285.                       "<!-- 1 -->\n" \
  286.                       "<blog>\n"\
  287.                       "\t<articolo id=\"1\">\n" \
  288.                       "\t\t<titolo>CMS Futaro</titolo>\n" \
  289.                       "\t\t<testo>Grazie per aver installato Futaro CMS.\n" \
  290.                       "Grazie a Futaro CMS, potrai gestire i tuoi dati, con totale sicurezza\n" \
  291.                       "e senza l'ausilio di un database!\n"
  292.                       "Per maggiori informazioni puoi contattare Futro all'indirizzo email: tafurok@gmail.com\n" \
  293.                       "\t\t</testo>\n" \
  294.                       "\t\t<autore>Futaro</autore>\n" \
  295.                       "\t\t<data>%d/%d/%d</data>\n" \
  296.                       "\t</articolo>\n" \
  297.                       "</blog>\n", time_s->tm_mday, (time_s->tm_mon + 1), (time_s->tm_year + 1900) );
  298.     return;
  299. }
  300.  
  301. void index_php_func (FILE *index)
  302. {
  303.     fprintf (index, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" \
  304.                        "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" \
  305.                        "<head>\n" \
  306.                        "\t<title> Simple - Blog </title>\n" \
  307.                        "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" \
  308.                        "</head>\n" \
  309.                        "<body>\n" \
  310.                        "\t<p align=left>\n" \
  311.                        "\t<font color=\"red\" size=\"10\"> Blog </font>" \
  312.                        "\t</p>\n" \
  313.                        "\t<\?php\n" \
  314.                        "\t\t$xml = simplexml_load_file(\'data.xml\');\n" \
  315.                        "\t\tforeach ( $xml->articolo as $articolo ) {\n" \
  316.                        "\t\t\tprint \"<h1><center>\" . $articolo->titolo . \"</h1></center><br />\" .\n" \
  317.                        "\t\t\t \"<p align=justify> <font color=\\\"black\\\" size=\\\"5\\\">\" . $articolo->testo . \"</font></p><br /><br />\" .\n" \
  318.                        "\t\t\t \"<p align=right> <font color=\\\"grey\\\" size=\\\"6\\\">\" . $articolo->autore . \"-->\" . $articolo->data . \"</font></p><br /><br />\" .\n" \
  319.                        "\t\t\t \"<hr /> <br />\";\n" \
  320.                        "\t\t}\n" \
  321.                        "\t\?>\n" \
  322.                        "\t<font size=\"1\"><p><a href=\"http://kevintafuro.altervista.orga\">Kevin Tafuro</a></p></font>\n" \
  323.                        "</body>\n");
  324.     return;
  325. }
  326.    
  327.  
  328. void add_new_article ()
  329. {
  330.     char username[20], ip[20], password[20]; /* usati per connettersi al server */
  331.     char titolo[30], testo[BUFSIZ], autore[20]; /* usati per comporre il corpo del messaggio */
  332.     char corpo[BUFSIZ]; /* usata per concatenare: il titolo, il testo e l'autore */
  333.     char buffer[BUFSIZ];
  334.     time_t raw_time; /* usata per prelevare l'ora */
  335.     struct tm *time_s; /* usata per poter stampare singoli pezzi della data */
  336.     struct sockaddr_in info_general, info_store, info_retrv; /* per le connessioni */
  337.     int sockfd_general, sockfd_store, sockfd_retrv; /* stream associati alle connessioni */
  338.     FILE *xml; /* per aprire e scrivere nel file xml */
  339.     int elemento = 0; /* usato per inizializzare il nuovo articolo inserito nel xml */
  340.    
  341.     printf ("Inserisci il tuo IP es: xx.xx.xx.xx : ");
  342.     scanf ("%s", ip);
  343.    
  344.     printf ("Inserisci il tuo username: ");
  345.     scanf ("%s", username);
  346.    
  347.     printf ("Inserici la tua password: ");
  348.     scanf ("%s", password);
  349.  
  350.     /* imposto lo stream socket e controllo eventuali errori */
  351.     sockfd_general = socket (AF_INET, SOCK_STREAM, 0);
  352.     if (sockfd_general < 0)
  353.     {
  354.         fprintf (stderr, "Errore nella creazione del socket!\n");
  355.         exit(EXIT_FAILURE);
  356.     }
  357.    
  358.     /* inizializzo la connessione */
  359.     inet_nexus (&info_general, inet_addr(ip), port_general);
  360.    
  361.     /* mi connetto all'host e controllo se ci sono errori */
  362.     if ( (connect (sockfd_general, (struct sockaddr *) &info_general, sizeof (struct sockaddr_in) ) ) < 0)
  363.     {
  364.         fprintf (stderr, "Erorre nella connessione al server!\n" \
  365.                          "Controlla se si ha impostato correttamente l'ip, l'username ed infine la password\n");
  366.         exit (EXIT_FAILURE);
  367.     }
  368.    
  369.     /*invio dati */
  370.     my_recv (sockfd_general, FALSO);
  371.     my_send (sockfd_general, "USER", username);
  372.     my_recv (sockfd_general, FALSO);
  373.     my_send (sockfd_general, "PASS", password);
  374.     my_recv (sockfd_general, FALSO);
  375.     my_send (sockfd_general, "CWD", "blog");
  376.     my_recv (sockfd_general, FALSO);
  377.     my_send (sockfd_general, "TYPE", "I");
  378.     my_recv (sockfd_general, FALSO);
  379.     my_send (sockfd_general, "PASV", "");
  380.     my_recv (sockfd_general, VERO);
  381.    
  382.     /* mi connetto alla nuova porta per il download dei file */
  383.     sockfd_retrv = socket (AF_INET , SOCK_STREAM, 0);
  384.     if (sockfd_retrv< 0)
  385.     {
  386.         fprintf (stderr, "Errore nella creazione del socket!\n");
  387.         exit (EXIT_FAILURE);
  388.     }
  389.    
  390.     inet_nexus (&info_retrv, inet_addr(ip), port_store);
  391.    
  392.     if ( (connect (sockfd_retrv, (struct sockaddr *) &info_retrv, sizeof (struct sockaddr_in) ) ) < 0)
  393.     {
  394.         fprintf(stderr, "Errore nella connessione al server!\n");
  395.         exit (EXIT_FAILURE);
  396.     }
  397.     my_send (sockfd_general, "RETR", FILE_XML);
  398.     my_recv (sockfd_general, FALSO);
  399.     retrv (sockfd_retrv, buffer);
  400.     my_recv (sockfd_general, FALSO);
  401.     close (sockfd_retrv);
  402.    
  403.     /* ottieni il numero di articoli inseriti dentro il database flat */
  404.     sscanf (buffer, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- %d -->", &elemento);
  405.    
  406.     /* incremento l'elemento */
  407.     ++elemento;
  408.    
  409.     while (getchar() != '\n'); /* svuoto il buffer */
  410.    
  411.     fprintf (stdout, "Inserisci il titolo dell'articolo: ");
  412.     fgets (titolo, sizeof (titolo), stdin);
  413.     titolo[strlen (titolo) - 1] = '\0'; /* elimino il new-line */
  414.    
  415.     fprintf (stdout, "Inserisci il testo dell'articolo. Per concludere premi invio:\n ");
  416.     fgets (testo, sizeof (testo), stdin);
  417.     testo[strlen (testo) - 1] = '\0';
  418.    
  419.     fprintf (stdout, "Inserisci l'autore: ");
  420.     fgets (autore, sizeof (autore), stdin);
  421.     autore[strlen (autore) - 1] = '\0';
  422.    
  423.     /* ottengo la data */
  424.     time (&raw_time);
  425.     time_s = localtime(&raw_time);
  426.    
  427.     /* apro il file per inserire i dati aggiornati */
  428.     xml = fopen (FILE_XML, "w");
  429.     if (xml == NULL)
  430.     {
  431.         fprintf (stderr, "Errore nella creazione del file %s\n", FILE_XML);
  432.         exit (EXIT_FAILURE);
  433.     }
  434.    
  435.     /* aggiorno il file aggiungendo il titolo il testo, l'autore, la data più il vecchio contenuto */
  436.     update (xml, elemento, titolo, testo, autore, time_s, buffer);
  437.    
  438.    
  439.     /* adesso devo rispedire il file */
  440.     my_send (sockfd_general, "PASV", "");
  441.     my_recv (sockfd_general, VERO);
  442.    
  443.     /* connetto alla nuova porta, inizializzando i dati */
  444.     sockfd_store = socket (AF_INET , SOCK_STREAM, 0);
  445.     if (sockfd_store < 0)
  446.     {
  447.         fprintf (stderr, "Errore nella creazione del socket!\n");
  448.         exit (EXIT_FAILURE);
  449.     }
  450.    
  451.     inet_nexus (&info_store, inet_addr(ip), port_store);
  452.    
  453.     if ( (connect (sockfd_store, (struct sockaddr *) &info_store, sizeof (struct sockaddr_in) ) ) < 0)
  454.     {
  455.         fprintf(stderr, "Errore nella connessione al server!\n");
  456.         exit (EXIT_FAILURE);
  457.     }
  458.     fprintf (stdout, "Invio i dati\n");
  459.     my_send (sockfd_general, "STOR", FILE_XML);
  460.     my_recv (sockfd_general, FALSO);
  461.     store (sockfd_store, FILE_XML);
  462.     my_recv (sockfd_general, FALSO);
  463.     close (sockfd_store);
  464.    
  465.     close (sockfd_general);
  466.    
  467.     remove (FILE_XML);
  468.    
  469.     fprintf(stdout, "Dati inviati con successo! Prova ad aggiornare la pagina.\n");
  470.    
  471.    
  472.     return;
  473. }
  474.  
  475. void update (FILE *stream, int n, char title[], char text[], char author[], struct tm *time_s, char buffer[])
  476. {
  477.     int contatore = 0;
  478.    
  479.     /* scrive nel file i nuovi dati ... */
  480.     fprintf (stream, "<\?xml version=\"1.0\" encoding=\"utf-8\"\?>\n" \
  481.                       "<!-- %d -->\n" \
  482.                       "<blog>\n"\
  483.                       "\t<articolo id=\"%d\">\n" \
  484.                       "\t\t<titolo>%s</titolo>\n" \
  485.                       "\t\t<testo>%s" \
  486.                       "\t\t</testo>\n" \
  487.                       "\t\t<autore>%s</autore>\n" \
  488.                       "\t\t<data>%d/%d/%d</data>\n" \
  489.                       "\t</articolo>\n", n, n, title, text, author, time_s->tm_mday, (time_s->tm_mon + 1), (time_s->tm_year + 1900) ); 
  490.      
  491.      n = 0;
  492.      
  493.      /* questo pasticcio mi permette di capire da dove devo iniziare a copiare */
  494.      while (1)
  495.      {
  496.          if (buffer[n] != '>')
  497.          {
  498.              n += 1;
  499.          } else {
  500.              n += 1;
  501.              contatore += 1;
  502.              if (contatore == 3)
  503.              {
  504.                  break;
  505.              }
  506.          }
  507.      }
  508.      
  509.      /* .. ed aggiunge quelli vecchi */
  510.      for (; buffer[n] != '\0'; n++)
  511.      {
  512.          fputc (buffer[n], stream);
  513.      }
  514.      
  515.      fclose (stream);
  516.      return;
  517. }
  518.    
  519.  
  520. void retrv (int sockfd, char buffer[])
  521. {
  522.     char buffer1[BUFSIZ];
  523.    
  524.     memset (buffer1, 0, sizeof (buffer1) ); /* azzero i due buffer */
  525.     memset (buffer, 0, sizeof (buffer) );
  526.    
  527.     /* finchè c'è qualche cosa da leggere leggi */
  528.     while (read (sockfd, buffer1, sizeof (buffer1) ) != 0) {
  529.         strncat (buffer, buffer1, strlen (buffer1) ); /* lo concatena al buffer */
  530.         memset (buffer1, 0, sizeof (buffer1) ); /* ri-azzera la memoria del buffer1 */
  531.     }
  532.     return;
  533. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement