Advertisement
Guest User

Untitled

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