Advertisement
Guest User

Untitled

a guest
Aug 12th, 2012
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <arpa/inet.h>
  6. #include <unistd.h>
  7.  
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11. int port = 22;
  12. char IP[]="10.42.43.81";
  13. char risp[410000];
  14. FILE *fp;
  15. int i,e=1;
  16. int server, err, byte;
  17. struct sockaddr_in server_addr;
  18. char buffer[]="GET /var/mobile/Media/DCIM/100APPLE/IMG_0298.PNG HTTP/1.1\r\nHost: 10.42.43.81 \r\n\r\n";
  19.  
  20.  
  21. // Creazione del socket
  22. server = socket(AF_INET, SOCK_STREAM, 0);
  23.  
  24. // Struttura relativa alle informazioni sul Server
  25. server_addr.sin_family = AF_INET;
  26. server_addr.sin_port = htons(port); //htons ---> host-order to network-order
  27. server_addr.sin_addr.s_addr = inet_addr(IP); // inet_addr converte da dotted_decimal in network-order
  28.  
  29. printf("\n\nConnessione in corso...\n");
  30.  
  31. // La funzione connect() restituisce un codice di errore
  32. err = connect (server, (struct sockaddr *)&server_addr, sizeof(server_addr));
  33. if(err == 0)
  34. {
  35. printf ("Connessione avvenuta\n");
  36. send (server,buffer,sizeof(buffer),0);
  37.  
  38. fp=fopen("image.png","w+");
  39. if (fp == NULL) printf ("Errore creazione file\n");
  40.  
  41. else {
  42.  
  43. int flag=1;
  44. //**************** problema :@
  45. while(e=recv (server, risp, sizeof(risp), 0)) {
  46. if (e<0) break; else {
  47. for (i=0;i<e;i++) {
  48. if (risp[i] == '\n' && flag!=5) flag++;
  49. //usleep(200);
  50. if (flag==5)
  51. fprintf(fp,"%c",risp[i]);
  52. }
  53. }
  54. }
  55. //***************************
  56. fclose(fp);
  57. }
  58. //printf ("n:%d\n",n);
  59. //printf ("\nServer: %s", risp);
  60.  
  61. }
  62. else
  63. {
  64. perror (buffer);
  65. }
  66.  
  67. printf("\n\n");
  68.  
  69. // Chiusura socket
  70. close(server);
  71.  
  72. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement